Skip to contents

Get URL query parameters in Shiny

Usage

params_get(session, keys = NULL)

Arguments

session

Shiny session

keys

Optional character vector of keys to pull; if NULL return all

Value

A named list containing the URL query parameters. If keys is specified, only those parameters are returned. If no parameters exist or the specified keys are not found, returns an empty list or list with NULL values respectively.

Examples

if (interactive()) {
server <- function(input, output, session) {
  # Get all query parameters
  all_params <- params_get(session)

  # Get specific parameters
  user_params <- params_get(session, keys = c("user_id", "token"))

  # Use in outputs
  output$params_display <- renderText({
    params <- params_get(session)
    if (length(params) > 0) {
      paste("Parameters:", jsonlite::toJSON(params))
    } else {
      "No parameters provided"
    }
  })
}
}