Debian Codegraph @

man/getQueryString.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/history.R
3 \name{getQueryString}
4 \alias{getQueryString}
5 \alias{getUrlHash}
6 \title{Get the query string / hash component from the URL}
7 \usage{
8 getQueryString(session = getDefaultReactiveDomain())
9
10 getUrlHash(session = getDefaultReactiveDomain())
11 }
12 \arguments{
13 \item{session}{A Shiny session object.}
14 }
15 \value{
16 For \code{getQueryString}, a named list. For example, the query
17 string \code{?param1=value1&param2=value2} becomes \code{list(param1 = value1, param2 = value2)}. For \code{getUrlHash}, a character vector with
18 the hash (including the leading \verb{#} symbol).
19 }
20 \description{
21 Two user friendly wrappers for getting the query string and the hash
22 component from the app's URL.
23 }
24 \details{
25 These can be particularly useful if you want to display different content
26 depending on the values in the query string / hash (e.g. instead of basing
27 the conditional on an input or a calculated reactive, you can base it on the
28 query string). However, note that, if you're changing the query string / hash
29 programmatically from within the server code, you must use
30 \verb{updateQueryString(_yourNewQueryString_, mode = "push")}. The default
31 \code{mode} for \code{updateQueryString} is \code{"replace"}, which doesn't
32 raise any events, so any observers or reactives that depend on it will
33 \emph{not} get triggered. However, if you're changing the query string / hash
34 directly by typing directly in the browser and hitting enter, you don't have
35 to worry about this.
36 }
37 \examples{
38 ## Only run this example in interactive R sessions
39 if (interactive()) {
40
41 ## App 1: getQueryString
42 ## Printing the value of the query string
43 ## (Use the back and forward buttons to see how the browser
44 ## keeps a record of each state)
45 shinyApp(
46 ui = fluidPage(
47 textInput("txt", "Enter new query string"),
48 helpText("Format: ?param1=val1&param2=val2"),
49 actionButton("go", "Update"),
50 hr(),
51 verbatimTextOutput("query")
52 ),
53 server = function(input, output, session) {
54 observeEvent(input$go, {
55 updateQueryString(input$txt, mode = "push")
56 })
57 output$query <- renderText({
58 query <- getQueryString()
59 queryText <- paste(names(query), query,
60 sep = "=", collapse=", ")
61 paste("Your query string is:\n", queryText)
62 })
63 }
64 )
65
66 ## App 2: getUrlHash
67 ## Printing the value of the URL hash
68 ## (Use the back and forward buttons to see how the browser
69 ## keeps a record of each state)
70 shinyApp(
71 ui = fluidPage(
72 textInput("txt", "Enter new hash"),
73 helpText("Format: #hash"),
74 actionButton("go", "Update"),
75 hr(),
76 verbatimTextOutput("hash")
77 ),
78 server = function(input, output, session) {
79 observeEvent(input$go, {
80 updateQueryString(input$txt, mode = "push")
81 })
82 output$hash <- renderText({
83 hash <- getUrlHash()
84 paste("Your hash is:\n", hash)
85 })
86 }
87 )
88 }
89 }
90 \seealso{
91 \code{\link[=updateQueryString]{updateQueryString()}}
92 }