Description Usage Arguments Value See Also Examples
View source: R/query-helpers.R
This function can be used to insert query parameters and values into the URL.
This function wraps shiny::updateQueryString()
, allowing individual
character strings or character vectors to be appended (default) or replace existing URL
query strings.
1 | insert_query_param(param, value, mode = "append")
|
param |
The parameter name. Can be a character string, e.g. "userID", or a character vector, such as c("userID", "favorite_food"). |
value |
The parameter value. Can be a character string, "jdtrat", or a character vector, such as c("jdtrat", "sushi"). |
mode |
Either "append" (default) to add a new query parameter/value pair to the existing URL or "replace" to replace any existing query parameters/values with new ones. |
NA; used for side effects to insert query strings in a Shiny application's URL.
Other Query Strings:
extract_query_param()
,
format_query_param()
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 45 46 47 48 49 50 | if (interactive()) {
library(shiny)
ui <- fluidPage(
actionButton("appendParam", "Append Query Parameters"),
actionButton("replaceParam", "Replace Query Parameters"),
verbatimTextOutput("query")
)
server <- function(input, output, session) {
observe({
# On start up, insert the following query string:
# "?person=jdt&food=sushi&best_cat=tucker"
if (session$clientData$url_search == "") {
insert_query_param(param = "startup-message",
value = "hello-world")
}
# print all query params
output$query <- renderText({
query_values <- vapply(
parseQueryString(session$clientData$url_search),
function(x) x, character(1)
)
query_params <- names(query_values)
paste0(query_params, ": ", query_values, "\n")
})
})
observeEvent(input$appendParam, {
insert_query_param(param = c("person", "food", "best_cat"),
value = c("jdt", "sushi", "tucker"),
mode = "append")
})
observeEvent(input$replaceParam, {
insert_query_param(param = "package",
value = "shinyrandomize",
mode = "replace")
})
}
shinyApp(ui, server)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.