2015-10-20 43 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')