2017-07-19 110 views
1

我正在創建一個閃亮的儀表板,它在側欄中有兩個選項卡。 Tab1用於導入csv和Tab2用於顯示所選變量的圖表。SideBar在儀表板主體上沒有渲染任何東西:R Shiny Dashboard

TAB2有1個選擇輸入選項選擇變量情節

問題:點擊側邊欄的選項卡後,我的儀表盤體不會改變。它總是向我顯示Tab1內容​​即csv導入結果。 因此,儘管點擊TAB2在側邊欄的,什麼也沒有發生

以下是我的腳本

library(shinydashboard) 
library(shiny) 
library(DT) 
#UI 

sidebar=dashboardSidebar(width=200, 
        sidebarMenu(id="sidebar", 
            menuItem("Data UpLoad", tabName = "dashboard", icon = icon("table"), 
              fileInput('file1','Choose CSV File', 
                accept=c('text/csv','text/comma-separated-values,text/plain', '.csv'))), 

            menuItem("Uni Variate", tabName = "Uni", icon = icon("line-chart"), 
              fluidRow(
              selectInput("options",label=h5("Select Column"),""))))) 


body= dashboardBody(
tabItems(
tabItem(tabName="dashboard",class='active', 
     fluidRow(
      box(
      title="Data",solidHeader = TRUE, collapsible = TRUE, 
      div(style='overflow-x: scroll',tableOutput("table1"))))), 

tabItem(tabName = "Uni", 
     fluidRow(box(title="Plot",solidHeader = TRUE,plotOutput("plot1"))), 
     h2("tab content")))) 

dashboardPage(
dashboardHeader(title= "test"),sidebar,body) 

#Server 
server <- function(input, output,session) { 
data_set <- reactive({ 
req(input$file1) 
inFile <- input$file1 
data_set1<-read.csv(inFile$datapath) 
list(data=data_set1) 
}) 
# updating select input of second tab in shiny side bar 
observe({ 
updateSelectInput(
    session, 
    "options", 
    choices = names(data_set()$data))}) 

# tab1 
output$table1= renderTable({ 
de=as.data.frame(data_set()$data[1:7,])}) 

#tab2 
output$plot1 <- renderPlot({ggplot(data_set$data,aes(y=input$options,x=Prediction))+geom_histogram(binwidth=0.50, fill="blue") }) 
} 

每個幫助是很重要的!

回答

2

看起來問題是關於將小部件放在側欄上,它將它們作爲子菜單。下面是幾個可能的解決方案,在側邊欄上放置小部件,具體取決於您是否希望在非活動時隱藏它們。

方案1級的小部件總是可見

library(shinydashboard) 
library(shiny) 

sidebar <- dashboardSidebar(width=200, 
    sidebarMenu(id="sidebar", 
    menuItem("Data UpLoad", icon = icon("table"), tabName = "dashboard"), 
    div(
     fileInput('file1','Choose CSV File', 
     accept=c('text/csv','text/comma-separated-values,text/plain', '.csv')) 
    ), 
    menuItem("Uni Variate", icon = icon("line-chart"), tabName = "Uni"), 
    div(
     selectInput("options",label=h5("Select Column"),"") 
    ) 
) 
) 

body <- dashboardBody(
    tabItems(
    tabItem(tabName="dashboard", class='active', 
     box(title="Data",solidHeader = TRUE, collapsible = TRUE, 
     div(style='overflow-x: scroll', p("table1")) 
    ) 
    ), 
    tabItem(tabName = "Uni", 
     box(title="Plot", solidHeader = TRUE, p("plot1")) 
    ) 
) 
) 

server <- function(input, output,session) {} 

shinyApp(dashboardPage(dashboardHeader(title= "test"), sidebar, body), server = server) 

選項只有2只小部件可見,當標籤被激活

請注意,以示對身體正確的選項卡,用戶必須點擊子項目。

library(shinydashboard) 
library(shiny) 

sidebar <- dashboardSidebar(width=200, 
    sidebarMenu(id="sidebar", 
     menuItem("data", icon = icon("table"), tabName = "dashboard", 
     menuSubItem(tabName = "dashboard", 
      fileInput('file1','Choose CSV File', 
      accept=c('text/csv','text/comma-separated-values,text/plain', '.csv')) 
    )), 
     menuItem("Uni Variate", icon = icon("line-chart"), tabName = "Uni", 
     menuSubItem(tabName = "Uni", 
      selectInput("options",label=h5("Select Column"),"") 
    )) 
) 
) 

body <- dashboardBody(
    tabItems(
    tabItem(tabName="dashboard", class='active', 
     box(title="Data",solidHeader = TRUE, collapsible = TRUE, 
     div(style='overflow-x: scroll', p("table1")) 
    ) 
    ), 
    tabItem(tabName = "Uni", 
     box(title="Plot", solidHeader = TRUE, p("plot1")) 
    ) 
) 
) 

server <- function(input, output,session) {} 

shinyApp(dashboardPage(dashboardHeader(title= "test"), sidebar, body), server = server) 
+0

是否有可能爲主菜單下的每個menusubItem提供輸入選項?如果是這樣,你能指導我一個例子嗎?當我嘗試這樣做時,表格/繪圖不會渲染。謝謝 – user5249203

相關問題