| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/utils.R |
| 3 |
\name{parseQueryString} |
| 4 |
\alias{parseQueryString} |
| 5 |
\title{Parse a GET query string from a URL} |
| 6 |
\usage{ |
| 7 |
parseQueryString(str, nested = FALSE) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{str}{The query string. It can have a leading \code{"?"} or not.} |
| 11 |
|
| 12 |
\item{nested}{Whether to parse the query string of as a nested list when it |
| 13 |
contains pairs of square brackets \code{[]}. For example, the query |
| 14 |
\samp{a[i1][j1]=x&b[i1][j1]=y&b[i2][j1]=z} will be parsed as \code{list(a = |
| 15 |
list(i1 = list(j1 = 'x')), b = list(i1 = list(j1 = 'y'), i2 = list(j1 = |
| 16 |
'z')))} when \code{nested = TRUE}, and \code{list(`a[i1][j1]` = 'x', |
| 17 |
`b[i1][j1]` = 'y', `b[i2][j1]` = 'z')} when \code{nested = FALSE}.} |
| 18 |
} |
| 19 |
\description{ |
| 20 |
Returns a named list of key-value pairs. |
| 21 |
} |
| 22 |
\examples{ |
| 23 |
parseQueryString("?foo=1&bar=b\%20a\%20r") |
| 24 |
|
| 25 |
\dontrun{ |
| 26 |
# Example of usage within a Shiny app |
| 27 |
function(input, output, session) { |
| 28 |
|
| 29 |
output$queryText <- renderText({ |
| 30 |
query <- parseQueryString(session$clientData$url_search) |
| 31 |
|
| 32 |
# Ways of accessing the values |
| 33 |
if (as.numeric(query$foo) == 1) { |
| 34 |
# Do something |
| 35 |
} |
| 36 |
if (query[["bar"]] == "targetstring") { |
| 37 |
# Do something else |
| 38 |
} |
| 39 |
|
| 40 |
# Return a string with key-value pairs |
| 41 |
paste(names(query), query, sep = "=", collapse=", ") |
| 42 |
}) |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
} |