I'm trying to generate a UI element that is dynamic based on how the user wishes to provide their input. I'm using the Shiny Dashboard for simplicity but I have encountered an issue with the sidebarMenu. Previously when I was placing static UI elements directly into the sidebarMenu, I had no issue, however when trying to place dynamic UI elements into the sidebarMenu I have problems. I'm using R 3.3.2 and Shiny 1.0.0 and Dashboard 0.5.3.
The specific problem I have is that when the program first loads up, the dynamic UI elements do not load. There does not appear to be any holdup in the code, as all the features of the interface work fine even while the dynamic UI is unloaded. I am able to get the dynamic UI to load by selecting one of the tabs in the navbar, or by hovering over something that I have implemented a tooltip on.
I am unable to provide the exact code but I have recreated a much smaller reproducible example that has all the same problems that my larger version does.
library("shiny")
library("shinydashboard")
header = dashboardHeader(
title = "Dynamic UI Example"
)
sidebar = dashboardSidebar(
sidebarMenu(
menuItemOutput("dynamic_sidebar")
)
)
body = dashboardBody(
tabBox(
tabPanel(
strong("One")
),
tabPanel(
strong("Two")
)
)
)
ui = dashboardPage(header, sidebar, body)
server = shinyServer(function(input,output,session){
output$dynamic_sidebar = renderMenu({
sidebarMenu(
menuItem(
"Slider or numeric problem",
radioButtons("slider_or_numeric",
label = "Slider or Numeric Input",
choices = c("Slider", "Numeric"),
selected = "Slider",
inline = TRUE
),
uiOutput("input")
)
)
})
output$input = renderUI({
if (input$slider_or_numeric == "Slider"){
sliderInput("slider",
label = "slider",
min = 0, max = 1,
value = 0
)
} else {
numericInput("numeric",
label = "numeric",
min = 0, max = 1,
value = 0
)
}
})
})
shinyApp(ui, server)
To verify the problem, after loading it up just open the menu item and you'll see the radio buttons but nothing else. Switch the tab on the navbar from one to two, and the input should appear in the menu (must be done while the menu is open).
I'm really just grasping at straws here, I have been troubleshooting this for hours and I think it's just an incompatibility with these features. I'm really hoping someone can prove me wrong and show me that I'm just doing it wrong. I've already found alternatives for my main program but they don't have the same aesthetic with what I'm trying to accomplish here.
Thanks for any and all help!