是否可以选择在shiny
应用程序首次启动时默认显示哪个tabItem ?我希望在"Information"
应用程序启动时显示第二个tabItem 。我尝试过selected=2
但没有运气。
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
dbHeader <- dashboardHeaderPlus(
titleWidth = "0px",
tags$li(a(
div(style="display: inline;margin-top:25px; padding: 0px 0px 0px 1250px;vertical-align:top; width: 150px;", actionButton("well", "Welcome",
style=" background-color: #faf0e6; font:Monserrat Light; border-color: #faf0e6")),
div(style="display: inline;margin-top:15px; padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("info", "Information",
style=" background-color: #faf0e6; border-color: #faf0e6"))
),
class = "dropdown")
)
shinyApp(
ui = dashboardPagePlus(
header = dbHeader,
sidebar = dashboardSidebar(width = "0px",
sidebarMenu(id = "sidebar", # id important for updateTabItems
menuItem("Welcome", tabName = "well", icon = icon("house")),
menuItem("Information", tabName = "info", icon = icon("table")),selected=2
) ),
body = dashboardBody(
useShinyjs(),
tags$script(HTML("$('body').addClass('fixed');")),
tags$head(tags$style(".skin-blue .main-header .logo { padding: 0px;}")),
tabItems(
tabItem("well",
paste("sdas")
),
tabItem("info"
)
)
)
),
server<-shinyServer(function(input, output,session) {
hide(selector = "body > div > header > nav > a")
observeEvent(input$well, {
updateTabItems(session, "sidebar", "well")
})
observeEvent(input$info, {
updateTabItems(session, "sidebar", "info")
})
}
)
)
您可以只updateTabItems
在函数的开头进行调用:
server <- shinyServer(function(input, output, session) {
hide(selector = "body > div > header > nav > a")
updateTabItems(session, "sidebar", "info")
...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句