/
query-string.Rmd
30 lines (27 loc) · 1.16 KB
/
query-string.Rmd
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
---
title: "query-string.Rmd"
subtitle: "Passing a query string value to R Markdown, see https://thomasswilliams.github.io/development/r/2022/08/19/r-markdown-querystring.html"
author: "Thomas Williams <https://github.com/thomasswilliams>"
output: html_document
runtime: shiny
params:
name: "Sam"
---
```{r echo = FALSE}
cat("Parameter \"name\" is", params$name)
```
```{r echo = FALSE}
# get the value of query string parameter "name"
# if missing, will be NULL
# "session$" is special Shiny variable (ignore "no variable...in scope" warning)
# needs to be wrapped in reactive
name <- shiny::reactive(shiny::parseQueryString(session$clientData$url_search)[["name"]])
# output value of query string parameter "name"
# need special syntax to get at reactive value, see
# https://mastering-shiny.org/reactive-motivation.html
cat("Query string \"name\" is:", shiny::isolate(name()))
# can test if we have a value using is.null
cat("Query string \"name\" is null?", is.null(shiny::isolate(name())))
```
<!-- output a link to take us to this same page, with a query string "name" of "Bob" -->
<h2><a href="query-string.Rmd?name=Bob">Click to pass query string "name" of "Bob"</a></h2>