extract_query_param: Extract parameters ID from query string

Description Usage Arguments Details Value See Also Examples

View source: R/query-helpers.R

Description

This function is useful for parsing individual parameters from a query string. It can be used both outside of and within a Shiny application.

Usage

1
extract_query_param(param, active_session = TRUE, query_string)

Arguments

param

The query parameter whose value should be retrieved.

active_session

LOGICAL: TRUE (default) for use in interactive shiny sessions. FALSE for parsing a character string supplied by query_string with query parameters.

query_string

If not run in an active session, the character string containing query parameters to parse.

Details

For use outside of a Shiny application, extract_query_param() is most similar to shiny::parseQueryString(), and within a Shiny application, it is most similar to shiny::getQueryString(). Both shiny functions return named lists of all query parameters and their values. In contrast, extract_query_param() returns a character string representing the value of the supplied parameter.

Value

The value from the requested query parameter.

See Also

Other Query Strings: format_query_param(), insert_query_param()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Outside of a Shiny application

extract_query_param(param = "best_cat",
                    active_session = FALSE,
                    query_string = "?person=jdt&favorite_food=sushi&best_cat=tucker")


# Within a Shiny application

if (interactive()) {

library(shiny)
library(shinyrandomize)

ui <- fluidPage(
  textInput("extractingParam", "Which parameter do you want to extract?"),
  verbatimTextOutput("query")
)

server <- function(input, output, session) {

  # On start up, insert the following query string:
  # "?person=jdt&favorite_food=sushi&best_cat=tucker"
  observe({
    if (session$clientData$url_search == "") {
      insert_query_param(param = c("person", "favorite_food", "best_cat"),
                         value = c("jdt", "sushi", "tucker"))
    }
  })

  # When one of the query parameters, 'person', 'food',
  # or 'best_cat' is specified, extract and show it.
  # The output will only appear for a valid parameter.
  observeEvent(input$extractingParam, {
    output$query <- renderText({
      extract_query_param(param = input$extractingParam)
    })
  })

}

shinyApp(ui, server)

}

jdtrat/shinyrandomize documentation built on Dec. 20, 2021, 10:06 p.m.