I'm setting up a shinydashboard app. Here is an example of a working UI:
shinyUI(dashboardPage(
dashboardHeader(title = tags$a("Learning Objectives",href='http://pluralsight.com',tags$img(src='logo.png'),
tags$head( tags$link(rel="stylesheet",type="text/css",href="pluralsight-theme.css"))
)
),
dashboardSidebar(
sidebarMenu(
menuItem("Content Search", tabname="search",icon=icon("magnifying-glass")),
menuItem("Course Report",tabname="course",icon=icon("file-lines"))
)
),
dashboardBody(
h2("hello there")
)
)
)
You can see I've defined menuItems but haven't used them yet. The menu items show up in the sidebar just fine. My css sheet just changes some colors, nothing fancy or breaking. Looks great.
Then, I try to implement the multi-tab:
shinyUI(dashboardPage(
dashboardHeader(title = tags$a("Learning Objectives",href='http://pluralsight.com',tags$img(src='logo.png'),
tags$head( tags$link(rel="stylesheet",type="text/css",href="pluralsight-theme.css"))
)
),
dashboardSidebar(
sidebarMenu(
menuItem("Content Search", tabname="search",icon=icon("magnifying-glass")),
menuItem("Course Report",tabname="course",icon=icon("file-lines"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = 'search', h2("hello there")),
tabItem(tabName = 'course',h2("hello there"))
)
)
)
)
This loads a blank dashboard. Clicking on the tabs does nothing.
CodePudding user response:
You have a typo calling menuItem
function. The argument should be tabName
, not tabname
.
Working app:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = tags$a("Learning Objectives",href='http://pluralsight.com',tags$img(src='logo.png'),
tags$head( tags$link(rel="stylesheet",type="text/css",href="pluralsight-theme.css"))
)
),
dashboardSidebar(
sidebarMenu(
menuItem("Content Search", tabName="search",icon=icon("magnifying-glass")),
menuItem("Course Report",tabName="course",icon=icon("file-lines"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = 'search', h2("hello there")),
tabItem(tabName = 'course',h2("hello there2"))
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)