在下面的示例代码中,当我按下“tab2”时,是否有一个服务器函数打开侧边栏面板中的“option2”?
ui <-
fluidPage(sidebarLayout(
sidebarPanel(h5("sidebar:"), width = 2, style = "position:right;top:70px;",
tabsetPanel(type = "pills",
tabPanel(title = "option1",
selectInput(inputId = "dataset",
label = "Dataset:",
choices = c(
"Example" = "example",
"Examle" = "example"),
selected = "example")),
tabPanel(title = "option2",
selectInput(inputId = "dataset",
label = "Dataset:",
choices = c(
"Example" = "example",
"example" = "example"),
selected = "example"),
))),
mainPanel(width = 10,
navbarPage(title = "tabs",
tabPanel("tab1",
fluidRow(
tabsetPanel(type = "pills",
),
mainPanel(width = 12, style = "height: 100vh; overflow-y: auto;",
fluidRow(
plotOutput("plot", height = "50vh"),
)))),
tabPanel("tab2",
fluidRow(
tabsetPanel(type = "pills",
),
mainPanel(width = 12, style = "height: 100vh; overflow-y: auto;",
fluidRow(
plotOutput("plot", height = "50vh"),
))))))))
server <- function(input, output)
shinyApp(ui = ui, server = server)
我尝试在服务器中使用observeEvent()
和observe()
使用面板的标签没有任何运气。
1条答案
按热度按时间li9yvcax1#
是的,
首先,你必须避免重复的id(
dataset
和plot
),否则什么都不能用。然后你必须在侧边栏中为TabSet面板分配一个ID,e例如
tabsetSidebar
,以及主面板中导航栏页面的ID,例如tabsetSidebar
。例如navbar
。然后,您可以在服务器中执行以下操作:下面是带有更正的UI: