How to dynamic display several numericInput based on another numericInput?

Hi community,
I would like to display several numericInput as defined by another numeriInput.

For example:
I have a numericInput, called "number_of_value", that is set to 4.
So dynamically the shiny app has to show 4 different numericInputs.
It is possible.
Here is my code

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(
    
    # Application title
    titlePanel("Old Faithful Geyser Data"),
    
    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30),
            
            numericInput("number_of_value",
                         "Select the number of numeric input",
                         value = 1,
                         max = 5,
                         step = 1),
            
            uiOutput("numeric_input_to_visualize")),
        
        # Show a plot of the generated distribution
        mainPanel(
            plotOutput("distPlot")
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
    
    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        
        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
    
    number <- reactive({
        input$number_of_value
    })
    
    output$numeric_input_to_visualize<-renderUI({
        lapply(number(), function(i) {
            numericInput(paste0("zone", i),
                         label = paste("Visualize the ", i),
                         min = 0,
                         max = 20000,
                         value = 50)
            
        })
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

Thanks

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.