Numeric Input

#| standalone: true
#| components: [viewer]
#| viewerHeight: 200

library(shiny)
library(bslib)

ui <- page_fixed(
  numericInput(
    "numeric",
    "Numeric input",
    value = 1,
    min = 1,
    max = 10
  ),
  verbatimTextOutput("value")
)

server <- function(input, output) {
  output$value <- renderText({ input$numeric })
}

shinyApp(ui, server)
library(shiny)
library(bslib)

ui <- page_fixed(
  numericInput( 
    "numeric", 
    "Numeric input", 
    value = 1, 
    min = 1, 
    max = 10 
  ), 
  verbatimTextOutput("value")
)

server <- function(input, output) {
  output$value <- renderText({ input$numeric })
}

shinyApp(ui, server)
No matching items

Relevant Functions

  • numericInput
    numericInput(inputId, label, value, min = NA, max = NA, step = NA, width = NULL)

No matching items

Details

A numeric input control creates a way to specify a number.

To add a numeric input control to your app:

  1. Add numericInput() to the UI of your app to create a numeric input. Where you call this function will determine where the numeric input control will appear within the app’s layout.

  2. Specify the inputId and label arguments of numericInput() to define the identifier and label of the numeric input. Specify the value argument to set the initial value. numericInput() also includes various optional parameters, including min and max, which set the minimum and maximum allowed values.

The value of an input component is accessible as a reactive value within the server() function. To access the value of a numeric input control:

  1. Use input$<numeric_input_id> (e.g., input$numeric) to access the specified numeric value. The server value of a numeric input control is a numeric vector of length 1.