R Markdown lets you add dynamic parameters to your report using the
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.
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
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)
additional named R objects, such as characters or lists, to transform into YAML
a Shiny function call to capture and convert to YAML
Display label for the control, or
NULL for no label.
Initial value (
The width of the input, e.g. '400px', or '100%'; see
Minimum allowed value
Maximum allowed value
Interval to use when stepping between min and max
TRUE to round all values to the nearest integer;
FALSE if no rounding is desired; or an integer to round to that
number of digits (for example, 1 will round to the nearest 10, and -2 will
round to the nearest .01). Any rounding will be applied after snapping to
the nearest step.
The format of the date to display in the browser. Defaults to
FALSE to hide tick marks,
TRUE to show them
according to some simple heuristics.
TRUE to show simple animation controls with default
FALSE not to; or a custom settings list, such as those created
Separator between thousands places in numbers.
A prefix string to put in front of the value.
A suffix string to put after the value.
Only used if the values are Date or POSIXt objects. A time
https://github.com/samsonjs/strftime for more details. The allowed
format specifications are very similar, but not identical, to those for R's
base::strftime() function. For Dates, the default is
"2015-07-01"), and for POSIXt, the default is
Only used if the values are POSIXt objects. A string
specifying the time zone offset for the displayed times, in the format
NULL (the default), times will
be displayed in the browser's time zone. The value
result in UTC time.
This option is used only if it is a range slider (with two
TRUE (the default), the range can be dragged. In other
words, the min and max can be dragged together. If
FALSE, the range
cannot be dragged.
The date range shown when the input object is first clicked. Can be "month" (the default), "year", or "decade".
Which day is the start of the week. Should be an integer from 0 (Sunday) to 6 (Saturday).
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".
Whether or not to close the datepicker immediately when a date is selected.
Which dates should be disabled. Either a Date object,
or a string in
Days of the week that should be disabled. Should be a integer vector with values from 0 (Sunday) to 6 (Saturday).
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.
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.
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:
A case insensitive extension like
A valid MIME type, like
image/* meaning any audio, video,
or image type, respectively.
The label used on the button. Can be text or an HTML tag object.
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
choiceValues must not
be provided, and vice-versa. The values should be strings; other types
(such as logicals and numbers) will be coerced to strings.
The initially selected value. If not specified, then it
defaults to the first item in
choices. To start with no items selected,
TRUE, render the choices inline (i.e. horizontally)
List of names and values, respectively, that
are displayed to the user in the app and correspond to the each choice (for
choiceValues must have the same length).
If either of these arguments is provided, then the other must be provided
choices must not be provided. The advantage of using both of these
over a named list for
choices is that
choiceNames allows any type of UI
object to be passed through (tag objects, icons, HTML code, ...), instead
of just simple text. See Examples.
Whether to use selectize.js or not.
Number of items to show in the selection box; a larger number
will result in a taller box. Not compatible with
multiple=FALSE, a select input will be a drop-down list,
size is set, it will be a box instead.
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) ) #> --- #> date: '`r format(Sys.Date())`' #> params: #> z: z #> x: #> input: numeric #> label: Starting value #> value: 23.0 #> 'no': #> input: checkbox #> label: No option? #> 'y': #> input: slider #> label: Data range #> min: 0.0 #> max: 1.0 #> value: 0.5 #> round: true #> --- #>