0

I have a shiny application reading an input from ui and I am unable to follow up with the data from the input in my code. As below:

ui <- fluidPage(

...
        selectInput("ISvModels", "Choose:", 
              choices = c(1000,5000)),
)

server <- function(input, output) {

  vModels <- reactive({input$ISvModels})
  qtModels <- length(vModels)
    qtModels
  vtModels <- paste0("M",1:qtModels," n = ",vModels," scenarios")
    vtModels
}

And I get:

Warning: Error in as.vector: cannot coerce type 'closure' to vector of type 'character'

I tried all sort of things from observe to renders but nothing works. Seems I'm missing some concepts here, hope you can help. Thanks!

1 Answers1

1

Your server needs an output, some way for what you've calculated to be shown to the user. We can use a textOutput to achieve this.

Below is a minimal example, showing a dropdown box linked to a textbox.

library(shiny)

ui <- fluidPage(
    
    #Dropdown
    selectInput("ISvModels", "Choose:", choices = c(1000,5000)),
    
    #Textbox
    textOutput("mytext")
    
)

server <- function(input, output, session) {
    
    #Prepare Textbox Content
    output$mytext <- renderText({
        
        qtModels <- length(input$ISvModels)
        vtModels <- paste0("M", 1:qtModels, " n = ", input$ISvModels," scenarios")

        return(vtModels)
        
    }) 
    
}

shinyApp(ui, server)
Ash
  • 1,463
  • 1
  • 4
  • 7