问题
Here's my ui.R and server.R. I'm not sure why the headers in dashboardBody don't show up.
server.R
shinyServer(function(input, output){
})
ui.R
dashboardPage(
dashboardHeader(title = "Analysis"),
dashboardSidebar(
sidebarMenu(
menuItem("Data Pull", tabName = "dataPull", icon = icon("database"),
dateInput("startDateInput", "What is the starting date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"),
dateInput("endDateInput", "What is the ending date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en")
),
menuItem("View Data", tabName = "dataView", icon = icon("table"),
selectInput("dataViewSelectionInput", label = "Selection of Interest?", choices = c(1,2,3), multiple = TRUE),
checkboxInput("dataViewAll", label = "View all pulled", value = TRUE)
)
)
),
dashboardBody(
tabItems(
tabItem(tabName = "dataPull",
h1("Data Selected")
),
tabItem(tabName = "dataView",
h2("Viewing Data")
)
)
)
)
回答1:
Currently, the dashboard seems to disallow switching to a tab and using a dropdown menu, I found a fix for it here:
add this function to the beginning of your UI, or your globals:
convertMenuItem <- function(mi,tabName) {
mi$children[[1]]$attribs['data-toggle']="tab"
mi$children[[1]]$attribs['data-value'] = tabName
mi
}
then your ui file becomes:
ui.R
dashboardPage(
dashboardHeader(title = "Analysis"),
dashboardSidebar(
sidebarMenu(
convertMenuItem(menuItem("Data Pull", icon = icon("database"),
dateInput("startDateInput", "What is the starting date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"),
dateInput("endDateInput", "What is the ending date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"),
tabName = "dataPull"),
tabName="dataPull"),
convertMenuItem(menuItem("View Data", icon = icon("table"),
selectInput("dataViewSelectionInput", label = "Selection of Interest?", choices = c(1,2,3), multiple = TRUE),
checkboxInput("dataViewAll", label = "View all pulled", value = TRUE),
tabName = "dataView"),
tabName="dataView")
)
),
dashboardBody(
tabItems(
tabItem(tabName = "dataPull",
h1("Data Selected")
),
tabItem(tabName = "dataView",
h2("Viewing Data")
)
)
)
)
This works because there is some default behavior in menuitem where if the menuItem has subitems, it won't set the data-toggle or data-value tags, so I set them manually. (Edited to remove a typo)
来源:https://stackoverflow.com/questions/31794702/r-shiny-dashboard-tabitems-not-apparing