Sample script:
library(shiny)
ui <- fluidPage(
selectInput("Select1","Name", c("Jack", "Daisy", "Mason")),
numericInput("num_balls", "Number of Balls", value = NA, step = 1))
server <- function(input, output,session) {
observeEvent(input$Select1,{
updateNumericInput(session, 'num_balls', label = "Number of Balls", value = NA, step = 1)
})
}
shinyApp(ui = ui, server = server)
I have a selectInput with three names - I would like for them to share a common numericInput box and for the value to be different for each option, say for e.g. Jack gets 3 balls, Daisy gets 4 balls, Mason gets 5, however I don't know what the correct syntax would be for this to work. I would like to be able to use the values I give for each option from Select1
in some other hypothetical part of the server script.
I've tried borrowing syntax for similar questions when searching for "dependent inputs" as my search expression, as seen here for example, which recommend using some form of observe_
or creating the UI in the server script through renderUI()
but I'm still not sure of the best way to create a numericInput which can serve multiple options from another input. As you can see in the example when I try and assign a number to a person, say Jack, then go to Daisy or Mason, then go back to Jack, the figure I entered disappears. I know this is because the value in updateNumericInput()
is always assigned to NA
.