在R和shiny
,我想使用shinydashboard
中的選項卡。儀表板通常有一個側欄,但對於一個標籤,我希望側邊欄消失以給頁面主體提供更多的屏幕空間。創建有條件的可見側邊欄閃亮
我知道有條件面板,但是當選項卡被激活時是否可以調整邊欄的可見性?
下面是一些模擬代碼,用於設置包含三個選項卡和側邊欄的shinydashboard。
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
# I would like to make the sidebar not visible if the third tab is selected...
# something like...
#if(input.tabs==3){dashboardSidebar(disable = TRUE)}else{dashboardSidebar()},
dashboardSidebar(),
if(input.tabs==3){dashboardSidebar(disable = TRUE)}else{dashboardSidebar()},
dashboardBody(
fluidRow(
column(width=12,
tabsetPanel(id='tabs'
tabPanel('tab1',
plotOutput('plot1'),value=1),
tabPanel('tab2',
plotOutput('plot2'),value=2),
tabPanel('tab3',
plotOutput('plot3'),value=3)
)
))
)
)
server <- function(input, output) {
output$plot1 <- renderPlot({
out <- ggplot(data.frame(X1=rnorm(1000)),aes(X1))+
geom_density(fill='light blue')+
theme_minimal()
print(out)
})
output$plot2 <- renderPlot({
out <- ggplot(data.frame(X1=rnorm(1000)),aes(X1))+
geom_density(fill='light blue')+
theme_minimal()
print(out)
})
output$plot3 <- renderPlot({
out <- ggplot(data.frame(X1=rnorm(1000)),aes(X1))+
geom_density(fill='light blue')+
theme_minimal()
print(out)
})
}
shinyApp(ui, server)
我得到運行下面的錯誤'警告(timeoutMs):在觀測 未處理的錯誤:參數爲長度爲零 觀察({ 如果(輸入$標籤== 3 ){ js $ hideSidebar() } })' –
您使用的是shinyjs v0.0.6.0嗎?有光澤的v0.12.0.9001?你是否複製了我的答案中的代碼?我忘了添加我的答案(我現在要編輯),我還必須將'session'參數添加到服務器功能中。 –
意識到我還需要安裝pacakge'V8'。切換回其他選項卡時,是否有辦法讓邊欄回來?即一旦側邊欄被「摺疊」,當點擊標籤2或1時,我怎麼能找回它? –