我在使用框标题中的updateTabItems()
和actionLink
更新标签时遇到问题。该问题可能与使用input$sidebarItemExpanded
(参见https://github.com/rstudio/shinydashboard/issues/167)有关。有任何解决方法的想法吗?
library(shiny)
library(shinydashboard)
# UI
ui <- dashboardPage(
dashboardHeader(title = "Title"),
dashboardSidebar(
sidebarMenu(
id="sidebarId",
menuItem("Tab 1 ",tabName="tab1",expandedName="tab1expanded",
menuSubItem("Submenu 1",tabName="submenu")
),
menuItem("Tab 2 ",tabName="tab2",expandedName="tab2expanded",
selectInput("select","Select Input",choices="Selection")
)
)
),
dashboardBody(
uiOutput("uiBody")
)
)
# Server
server <- function(input, output,session) {
observeEvent(input$link,{
updateTabItems(session,"sidebarId","tab2")
})
output$uiBody <- renderUI({
if (req(input$sidebarItemExpanded)=="tab1expanded"){
tabItems(
tabItem("submenu",
box(status="primary",solidHeader=T,
title=actionLink("link","Link to tab 2")
)
)
)
} else if (req(input$sidebarItemExpanded)=="tab2expanded"){
h2("Tab2")
}
})
}
shinyApp(ui = ui, server = server)