【问题标题】:Enabling a scrollbar in rpivotTable using shiny services使用闪亮服务在 rpivotTable 中启用滚动条
【发布时间】:2016-01-19 00:17:23
【问题描述】:

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

我已成功设置 ui.R 和 server.R ui.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


    【解决方案1】:

    问题在于您的 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”。

    【讨论】:

    • 谢谢 - 您的回答解决了问题 - 我从 github 获取了代码,但没有声明 CSS 选择器。我现在已经做到了,感谢流体行的建议。实际上我正在使用它,但是当我无法让滚动工作时,我已经从我的代码中删除了它。
    • 当然可以,很高兴我能帮上忙!如果您认为这解决了您的问题,请随时将问题标记为已回答。
    【解决方案2】:

    您应该考虑的唯一一件事是在 CSS 代码之前传递完全相同的 id,因此在此代码中将 #test 替换为 #PivotTable 和宾果游戏...您的代码应该可以工作...

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

    【讨论】:

      猜你喜欢
      • 2015-08-12
      • 2016-08-01
      • 2023-03-27
      • 1970-01-01
      • 2019-02-22
      • 2016-11-03
      • 2018-04-13
      • 2016-07-28
      • 2020-03-04
      相关资源
      最近更新 更多