使用闪亮的服务在rpivotTable中启用滚动条

问题描述 投票:1回答:2

我正在使用在Red Hat Linux版本6.5上托管的R-3.2.0,带有闪亮的软件包(版本0.12.0)。我正在尝试使用Shinydashboard功能来设计一些报告。 RStudio版本为0.98.1103

我已经成功设置了ui.R和server.Rui.R-:

ibrary(shinydashboard)
library(htmlwidgets)
library(rpivotTable)
library(leaflet)

dashboardPage(
  dashboardHeader(title="Reports",
                  dropdownMenu(type = "task",
                               messageItem(
                                 from = "Download",
                                 message = "test",
                                 icon = icon("gear")
                               ),
                               messageItem(
                                 "Download",
                                 message = "TEST",
                                 icon = icon("life-ring"),
                                 href= "http://www.google.com"
                               )
                  )

    ),

  dashboardSidebar(
    sidebarMenu(
     menuItem("Srts", tabName = "ServiceItems", icon = icon("dashboard"))
    )
    ),

  dashboardBody(
                tags$head(tags$style(
                type = 'text/css',
                '#test{ overflow-x: scroll; }')),
                rpivotTableOutput('PivotTable')
               )
             )

server.R-:

library(shiny)
library(ggplot2)
library(wordcloud)
library(devtools)
library(htmlwidgets)
library(rpivotTable)
library(leaflet)

shinyServer(function(input, output) {
  PivotTable <- read.csv("Book2.csv",head=TRUE,sep= ',')
  output$PivotTable <- rpivotTable::renderRpivotTable({
  rpivotTable(PivotTable, rows="Ar", col="DTM", aggregatorName="Count",
              vals="Ar", rendererName="Table")})
  tableFirst<-as.data.frame(sort(table(PivotTable$Area),decreasing=TRUE))
})

以下用于在仪表板主体中滚动的代码摘自https://github.com/smartinsightsfromdata/rpivotTable/issues/19:-

        tags$head(tags$style(
        type = 'text/css',
        '#test{ overflow-x: scroll; }')),
        rpivotTableOutput('PivotTable')

我面临的问题是,添加以帮助滚动的代码不起作用。我已经删除了所有标签,布局等的代码,但仍然可以滚动使用。

我已经观察到,如果我删除了dashboardPage命令,滚动确实可以进行,但是显示非常笨拙并且不能真正呈现出来。


但是,当我按以下方式组合代码(在RStudio中)并运行滚动时,效果很好。

library(shiny)
library(shinydashboard)
library(rpivotTable)
library(ggplot2)

PivotTable <- read.csv("Book2.csv",head=TRUE,sep= ',')
header <-   dashboardHeader(title="Reports",
                  dropdownMenu(type = "task",
                               messageItem(
                                 from = "Download",
                                 message = "test",
                                 icon = icon("gear")
                               ),
                               messageItem(
                                 "Download",
                                 message = "TEST",
                                 icon = icon("life-ring"),
                                 href= "http://www.google.com"
                               )
                  )

    )

sidebar <- dashboardSidebar()
body <- dashboardBody(
                      tags$head(tags$style(HTML('
                      .skin-blue.main-header .logo {
                      background-color: #3c8dbc;
                     }
                     .skin-blue .main-header .logo:hover {
                     background-color: #3c8dbc;
                     }
                   '))
                     ),
                     tags$head(tags$style(type = 'text/css',
                    '#test{ overflow-x: scroll; }')),
                     rpivotTableOutput("test")
                     )            

                     shinyApp(
                     ui = dashboardPage(header, sidebar, body),
                     server = function(input, output) {
                     output$test <- rpivotTable::renderRpivotTable({
                     rpivotTable(PivotTable, rows="Ar", col="DTM",                     aggregatorName="Count",vals="Ar", rendererName="Table")})
                })

但是,我无法将其作为最终解决方案,因为需要此解决方案的业务用户并不擅长在RStudio上复制和粘贴代码(如果可以的话,我可以像平常一样使用组合的代码。还要考虑)。


有人可以帮我理解防止滚动的原始代码问题。

非常感谢!

r shiny shinydashboard rpivottable
2个回答
0
投票

问题是您的CSS选择器,否则一切正常。您在具有ID测试的元素上设置了滚动属性,但在您的示例中找不到具有该ID的元素。尝试这样的事情:

library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(),
  dashboardBody(
    tags$head(
      tags$style(
        HTML("
            #myScrollBox{ 
              overflow-y: scroll; 
              overflow-x: hidden; 
              height:120px;
            }
             ")
      )
    ),
    # Boxes need to be put in a row (or column)
    fluidRow(
      div(id="myScrollBox",
        plotOutput("plot1", height = 250)),

      box(
        title = "Controls",
        sliderInput("slider", "Number of observations:", 1, 100, 50)
      )
    )
  )
)

server <- function(input, output) {
  set.seed(122)
  histdata <- rnorm(500)

  output$plot1 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })
}

shinyApp(ui, server)

您需要将CSS选择器更改为要添加滚动的元素,在示例中为“ myScrollBox”。


0
投票

您唯一需要考虑的是在CSS代码之前传递完全相同的id,因此在此代码中,将#test替换为#PivotTable并进行宾果游戏...您的代码应工作...

tags$head(tags$style(
    type = 'text/css',
    '#test{ overflow-x: scroll; }')),
    rpivotTableOutput('PivotTable')
© www.soinside.com 2019 - 2024. All rights reserved.