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)
Relevant Functions
-
numericInput
numericInput(inputId, label, value, min = NA, max = NA, step = NA, width = NULL)
Details
A numeric input control creates a way to specify a number.
To add a numeric input control to your app:
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.Specify the
inputId
andlabel
arguments ofnumericInput()
to define the identifier and label of the numeric input. Specify thevalue
argument to set the initial value.numericInput()
also includes various optional parameters, includingmin
andmax
, 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:
- 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.