yml_params {ymlthis} | R Documentation |
Parameterize an R Markdown report using Shiny components
Description
R Markdown lets you add dynamic parameters to your report using the params
YAML field (see the R Markdown book for
examples); parameterized reports are also used in RStudio Connect. The values
of these variables can be called inside your R Markdown document using
params$field_name
. There are several ways to change the values of the parameters: manually
change the YAML, use the params
argument in rmarkdown::render()
, or knit
with parameters, which launches a Shiny app to select values for each.
yml_params()
accepts any number of named R objects to set as YAML fields.
You can also pass arguments to the underlying Shiny functions using YAML. To
set a shiny component, use the shiny_*()
helper functions. shiny_params()
captures a Shiny output function and transforms it to YAML. However, R
Markdown supports only a limited number of components; each of these is
included as a function starting with shiny_*()
, e.g. shiny_checkbox()
Usage
yml_params(.yml, ...)
shiny_params(.shiny)
shiny_checkbox(label, value = FALSE, width = NULL)
shiny_numeric(label, value, min = NA, max = NA, step = NA, width = NULL)
shiny_slider(
label,
min,
max,
value,
step = NULL,
round = FALSE,
format = NULL,
ticks = TRUE,
animate = FALSE,
width = NULL,
sep = ",",
pre = NULL,
post = NULL,
timeFormat = NULL,
timezone = NULL,
dragRange = TRUE
)
shiny_date(
label,
value = NULL,
min = NULL,
max = NULL,
format = "yyyy-mm-dd",
startview = "month",
weekstart = 0,
language = "en",
width = NULL,
autoclose = TRUE,
datesdisabled = NULL,
daysofweekdisabled = NULL
)
shiny_text(label, value = "", width = NULL, placeholder = NULL)
shiny_file(
label,
multiple = FALSE,
accept = NULL,
width = NULL,
buttonLabel = "Browse...",
placeholder = "No file selected"
)
shiny_radio(
label,
choices = NULL,
selected = NULL,
inline = FALSE,
width = NULL,
choiceNames = NULL,
choiceValues = NULL
)
shiny_select(
label,
choices,
selected = NULL,
multiple = FALSE,
selectize = TRUE,
width = NULL,
size = NULL
)
shiny_password(label, value = "", width = NULL, placeholder = NULL)
Arguments
.yml |
a |
... |
additional named R objects, such as characters or lists, to transform into YAML |
.shiny |
a Shiny function call to capture and convert to YAML |
label |
Display label for the control, or |
value |
Initial value ( |
width |
The width of the input, e.g. '400px', or '100%'; see
|
min |
Minimum allowed value |
max |
Maximum allowed value |
step |
Interval to use when stepping between min and max |
round |
|
format |
The format of the date to display in the browser. Defaults to
|
ticks |
|
animate |
|
sep |
Separator between thousands places in numbers. |
pre |
A prefix string to put in front of the value. |
post |
A suffix string to put after the value. |
timeFormat |
Only used if the values are Date or POSIXt objects. A time
format string, to be passed to the Javascript strftime library. See
https://github.com/samsonjs/strftime for more details. The allowed
format specifications are very similar, but not identical, to those for R's
|
timezone |
Only used if the values are POSIXt objects. A string
specifying the time zone offset for the displayed times, in the format
|
dragRange |
This option is used only if it is a range slider (with two
values). If |
startview |
The date range shown when the input object is first clicked. Can be "month" (the default), "year", or "decade". |
weekstart |
Which day is the start of the week. Should be an integer from 0 (Sunday) to 6 (Saturday). |
language |
The language used for month and day names. Default is "en". Other valid values include "ar", "az", "bg", "bs", "ca", "cs", "cy", "da", "de", "el", "en-AU", "en-GB", "eo", "es", "et", "eu", "fa", "fi", "fo", "fr-CH", "fr", "gl", "he", "hr", "hu", "hy", "id", "is", "it-CH", "it", "ja", "ka", "kh", "kk", "ko", "kr", "lt", "lv", "me", "mk", "mn", "ms", "nb", "nl-BE", "nl", "no", "pl", "pt-BR", "pt", "ro", "rs-latin", "rs", "ru", "sk", "sl", "sq", "sr-latin", "sr", "sv", "sw", "th", "tr", "uk", "vi", "zh-CN", and "zh-TW". |
autoclose |
Whether or not to close the datepicker immediately when a date is selected. |
datesdisabled |
Which dates should be disabled. Either a Date object,
or a string in |
daysofweekdisabled |
Days of the week that should be disabled. Should be a integer vector with values from 0 (Sunday) to 6 (Saturday). |
placeholder |
A character string giving the user a hint as to what can be entered into the control. Internet Explorer 8 and 9 do not support this option. |
multiple |
Whether the user should be allowed to select and upload multiple files at once. Does not work on older browsers, including Internet Explorer 9 and earlier. |
accept |
A character vector of "unique file type specifiers" which gives the browser a hint as to the type of file the server expects. Many browsers use this prevent the user from selecting an invalid file. A unique file type specifier can be:
|
buttonLabel |
The label used on the button. Can be text or an HTML tag object. |
choices |
List of values to select from (if elements of the list are
named then that name rather than the value is displayed to the user). If
this argument is provided, then |
selected |
The initially selected value. If not specified, then it
defaults to the first item in |
inline |
If |
choiceNames , choiceValues |
List of names and values, respectively, that
are displayed to the user in the app and correspond to the each choice (for
this reason, |
selectize |
Whether to use selectize.js or not. |
size |
Number of items to show in the selection box; a larger number
will result in a taller box. Not compatible with |
Value
a yml
object
See Also
Other yml:
asis_yaml_output()
,
bib2yml()
,
draw_yml_tree()
,
has_field()
,
read_json()
,
use_yml_defaults()
,
use_yml_file()
,
use_yml()
,
yml_author()
,
yml_blogdown_opts()
,
yml_bookdown_opts()
,
yml_citations()
,
yml_clean()
,
yml_distill_opts()
,
yml_latex_opts()
,
yml_output()
,
yml_pagedown_opts()
,
yml_pkgdown()
,
yml_reference()
,
yml_replace()
,
yml_resource_files()
,
yml_rsconnect_email()
,
yml_rticles_opts()
,
yml_runtime()
,
yml_site_opts()
,
yml_toc()
,
yml_vignette()
Other R Markdown:
yml_clean()
,
yml_runtime()
,
yml_site_opts()
,
yml_vignette()
Other shiny:
yml_runtime()
Examples
yml() %>%
yml_params(
z = "z",
x = shiny_numeric("Starting value", 23),
no = shiny_checkbox("No option?"),
y = shiny_slider("Data range", 0, 1, .5, round = TRUE)
)