Reputation: 1772
The UI doesn't update the page when I have an input in the sidebar menu. In the example below when I click on "load data" it still shows a menu on the page.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("About", tabName = "a", icon = icon("info-circle")),
menuItem("Load Data", icon = icon("gear"), tabName = "b",
selectInput(inputId="convertToLog", label="Are X values on log2 scale?",choices=list('Yes'=1,'No'=0),selected=1))
)),
dashboardBody(
tabItems(
tabItem(tabName ="a", "a menu"),
tabItem(tabName ="b", "b menu")
)
)
)
server <- function(input, output) {}
shinyApp(ui, server)
Upvotes: 1
Views: 681
Reputation: 25435
As far as I know, you can/should not put another item in a menuItem
, except for subMenuItems
. You could use a conditionalPanel
to achieve what you want though:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(id="mysidebar",
menuItem("About", tabName = "a", icon = icon("info-circle")),
menuItem("Load Data", icon = icon("gear"), tabName = "b"),
conditionalPanel("input.mysidebar == 'b'",
selectInput(inputId="convertToLog", label="Are X values on log2 scale?",choices=list('Yes'=1,'No'=0),selected=1)),
menuItem('Another tab',tabName='c',icon = icon("gear"))
)
),
dashboardBody(
tabItems(
tabItem(tabName ="a", "a menu"),
tabItem(tabName ="b", "b menu"),
tabItem(tabName ="c", "c menu")
)
)
)
server <- function(input, output) {}
shinyApp(ui, server)
Note that I gave the sidebarMenu
an ID to use in the condition of the conditionalPanel
, and I added a tab to show that the conditionalPanel
does not have to be at the bottom of the menu.
I hope this helps!
Upvotes: 2