如果侧边栏菜单是动态创建的,则内容不会显示在仪表板正文中
Content doesn't show up in the dashboard body if the sidebar menu is dynamically created
我注意到如果侧边栏菜单是由服务器代码动态创建的,则在应用程序加载时直到单击选项卡后才会显示内容。
在示例中,我使用了闪亮的仪表板入门页面中的示例代码。该应用程序按预期运行。但是,如您所见,我将侧边栏菜单更改为动态创建,应用程序加载时会显示一个空白页面。我必须单击侧边栏的第一个选项卡才能打开页面。有没有办法显示默认页面,即仪表板标签页?请注意,我在闪亮的仪表板 github 页面上输入了一个问题。非常感谢您的帮助。
`## app.R ##
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
## Sidebar content
# dashboardSidebar(
# sidebarMenu(
# menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
# menuItem("Widgets", tabName = "widgets", icon = icon("th"))
# )
# ),
dashboardSidebar(width=150, sidebarMenuOutput("sideMenu")
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "dashboard",
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
),
# Second tab content
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
)
server <- function(input, output, session) {
output$sideMenu <- renderMenu({
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
})
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)`
您需要将其中一个选项卡设置为活动状态。
例如:
# First tab content
tabItem(tabName = "dashboard", class = "active",
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
),
我注意到如果侧边栏菜单是由服务器代码动态创建的,则在应用程序加载时直到单击选项卡后才会显示内容。
在示例中,我使用了闪亮的仪表板入门页面中的示例代码。该应用程序按预期运行。但是,如您所见,我将侧边栏菜单更改为动态创建,应用程序加载时会显示一个空白页面。我必须单击侧边栏的第一个选项卡才能打开页面。有没有办法显示默认页面,即仪表板标签页?请注意,我在闪亮的仪表板 github 页面上输入了一个问题。非常感谢您的帮助。
`## app.R ##
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
## Sidebar content
# dashboardSidebar(
# sidebarMenu(
# menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
# menuItem("Widgets", tabName = "widgets", icon = icon("th"))
# )
# ),
dashboardSidebar(width=150, sidebarMenuOutput("sideMenu")
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "dashboard",
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
),
# Second tab content
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
)
server <- function(input, output, session) {
output$sideMenu <- renderMenu({
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
})
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)`
您需要将其中一个选项卡设置为活动状态。
例如:
# First tab content
tabItem(tabName = "dashboard", class = "active",
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
),