【发布时间】:2022-01-06 13:03:49
【问题描述】:
在下面的代码中,我正在创建一个基于所选选项卡的动态sidebarMenu。在此应用程序的初始加载期间,即使只选择了tab 1,也会呈现两个选项卡的sidebarMenu。在我的原始应用程序中,这会导致加载时间延迟,因为我在每个选项卡上都有很多控件。
在加载应用程序时,有没有办法只加载活动选项卡的侧边栏控件,而不是加载两个选项卡的侧边栏控件?
library(shiny)
library(shinydashboard)
sidebar <- dashboardSidebar(
collapsed = FALSE,
sidebarMenu(
id = "menu_sidebar",
conditionalPanel(
condition = "input.main_tab == 'tab 1'",
selectizeInput(inputId = "t1", label = "Select by:", choices = c(as.character(30:40))),
print("Hello Tab 1")
),
conditionalPanel(
condition = "input.main_tab == 'tab 2'",
selectizeInput(inputId = "t2", label = "Select by:", choices = c(as.character(40:50))),
print("Hello Tab 2")
)
)
)
body <- dashboardBody(
fluidRow(
tabsetPanel(
id = "main_tab",
selected = "tab 1",
tabPanel(title = "tab 1", "Tab content 1"),
tabPanel(title = "tab 2", "Tab content 2")
)
)
)
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "tabBoxes"),
sidebar,
body
),
server = function(input, output) {
}
)
【问题讨论】:
标签: r shiny shinydashboard shiny-server shinyapps