rstudio/shiny — pull request #122 by wch (2013-03-11 17:34:10+00:00)
Title: Send URL components in clientData

This branch sends URL components in clientData.

For example, if you use the URL http://localhost:8100/?foo=a%20b&bar=bar2&novalue=&=nokey, then clientData will have these values:

```
url_hostname = localhost
url_pathname = /
url_port = 8100
url_protocol = http:
url_search = ?foo=a%20b&bar=bar2&novalue=&=nokey
```

Additionally, the `parseQueryString` function will do this:

```
parseQueryString('?foo=a%20b&bar=bar2&novalue=&=nokey')
$foo
[1] "a b"

$bar
[1] "bar2"

$novalue
[1] ""

[[4]]
[1] "nokey"
```

It can be called from inside an app by using `parseQueryString(clientData$url_search)`.

This sample app demonstrates what it does:

```
# First, install correct version of shiny
install_github('shiny', 'wch', 'url')

downloader::source_url("https://gist.github.com/wch/5003044/raw/aa4dbbca0023e29a629386b1ee9a5d27b2e37362/shinyserialize.r")

shinyRun(
#--------------------------------------------------------------
`server.r` = quote({
shinyServer(function(input, output, clientData) {

output$plot <- renderPlot({
hist(rnorm(input$obs))
})

# Print out clientData
output$summary <- renderText({
cnames <- names(clientData)
allvalues <- lapply(cnames, function(name) paste(name, clientData[[name]], sep=" = "))
paste(allvalues, collapse = "\n")
})

# Parse the GET query
output$queryText <- renderText({
query <- parseQueryString(clientData$url_search)

# Return a string with key-value pairs
paste(names(query), query, sep = "=", collapse=", ")
})

})
}),
#--------------------------------------------------------------
`ui.r` = quote({
shinyUI(pageWithSidebar(
headerPanel("Shiny Client Data"),
sidebarPanel(
sliderInput("obs", "Number of observations:", min = 0, max = 1000, value = 500)
),
mainPanel(
h3("clientData values"),
verbatimTextOutput("summary"), # clientData values
h3("Parsed URL query"),
verbatimTextOutput("queryText"), # clientData values
plotOutput("plot")
)
))
})
)
```