I believe the issue is trying to put a dashboardPage() as an internal UI output. If I trim it down to just dashboardBody(), the code works as expected.
If you'd like all three parts, I would use three independent renderUI() methods. One for the header, sidebar, and body.
Updated app:
library("shiny")
library("shinydashboard")
ui <- fluidPage(
actionButton("create_scenario", "Create Scenario"),
actionButton("load_scenario","load scenario"),
uiOutput("input"),
uiOutput("inputs")
)
server <- function(input, output,session) {
state <- reactiveVal("none")
observeEvent(input$create_scenario,{
state("create")
})
observeEvent(input$load_scenario,{
state("load")
})
output$inputs <- renderUI({
req(state())
state_val <- state()
if (state_val == "create") {
textInput("txtInput","Enter Scenario Name","Enter name as scenario
(number of senario created +1)")
} else if (state_val == "load") {
# dashboardPage(
# dashboardHeader(title = "Basic dashboard"),
# dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
)
# )
} else {
NULL
}
})
histdata <- rnorm(500)
output$plot1 <- renderPlot({
req(input$slider)
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)
Side reactivity goal: try to keep render* statements outside of observe* executions. Instead, in observe* methods set data values that can be read inside render* methods.
The example above uses state() to determine what is displayed in the dashboard body.