0

In my code when load scenario button is clicked it should display a dashboard.But i am getting error "object of type 'closure' is not subsettable".I know there are lot of questions already asked in stack overflow but i am unable to get any of these Here is my code

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) {

 observeEvent(input$create_scenario,{

   output$input <- renderUI({
     textInput("txtInput","Enter Scenario Name","Enter name as scenario         
(number of senario created +1)")
    })


 })

  observeEvent(input$load_scenario,{

  output$inputs <- renderUI({
  # textInput("txtInput","Enter Scenario Name","Enter name as scenario  
 #(number of senario created +1)")
        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)
      ))))

  histdata <- rnorm(500)
output$plot1 <- renderPlot({
  data <- histdata[seq_len(input$slider)]
hist(data)
})

 } )


 })
}
shinyApp(ui, server)
user11034850
  • 35
  • 1
  • 9
  • Anything inside `renderUI` is static since it's User Interface so `output$plot1` won't be calculated and therefore will raise an error. move `histdata <- rnorm(500) output$plot1 <- renderPlot({ data <- histdata[seq_len(input$slider)] hist(data) })` outside `renderUI` and inside `obserEvent`. Also note you will need to click `load scenario` twice to get your plot, I don't know why. – A. Suliman Apr 20 '19 at 11:43
  • 1
    Thank you very much for your help @A.Suliman – user11034850 Apr 20 '19 at 12:55

0 Answers0