2015-10-20 94 views
1

我使用的是R-3.2.0,它是在Red Hat Linux 6.5版上托管的闪亮包(版本0.12.0)。我正在尝试利用shinydashboard功能来设计一些报告。该RStudio版本0.98.1103使用闪亮的服务在rpivotTable中启用滚动条

我已经成功地建立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(如果有,我可以用结合的编码就像一个可能的方式通常我可以考虑这一点)。


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

非常感谢!

回答

0

问题是你的CSS选择器,否则一切看起来都OK。你在ID测试的元素上设置scroll-property,但是在你的例子中我找不到具有这个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

谢谢 - 你的答案照顾它 - 我从github的代码,但没有声明的CSS选择器。我现在已经这样做了,并感谢fluidRow的建议。其实我正在使用它,但是当我无法让滚动工作时,我已经从代码中删除了它。 – rantish

+0

当然,很高兴我能帮上忙!如果您觉得这解决了您的问题,请随时将问题标记为已回答。 –

0

,你应该采取在审议的唯一事情是CSS代码前通过完全相同的ID,所以在此代码替换#TEST#PivotTable和宾果...您的代码应工作。 ..

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