Learn R Programming

rlc (version 0.5.0)

lc_input: Add input forms to the page

Description

lc_input adds an input form. This function is an rlc wrapper for an HTML <input> tag. Five types of input are supported: "text", "range", "checkbox", "radio" and "button".

Usage

lc_input(data = list(), place = NULL, ..., chartId = NULL, with = NULL)

Arguments

data

Name-value pairs of properties passed through the dat function. These properties will be re-evaluated on each updateCharts call.

place

An ID of the container, where to place new chart. It will be ignored if the chart already exists. If not defined, the chart will be appended to the web page's body.

...

Name-value pairs of properties that will be evaluated only once and then will remain constant. These properties can still be changed later using the setProperties function.

chartId

An ID for the chart. All charts must have unique IDs. If a chart with the same ID already exists, it will be replaced. If ID is not defined, it will be the same as the value of the place argument. And if both are not defined, the ID will be set to ChartN, where N - 1 is the number of existing charts.

with

A dataset or a list from which other properties should be taken. If the dataset doesn't have a column with the requested name, the variable will be searched for outside of the dataset. Must be a data.frame or a list.

Available properties

You can read more about different properties here.

  • type - type of input. Must be one of "text", "range", "checkbox", "radio" or "button".

  • value - current state of the input block. For radio buttons it is an index of the checked button. For checkboxes - a vector of TRUE (for each checked box) and FALSE (for each unchecked ones), for ranges and text boxes - a vector of values for each text field or slider.

  • step (only for type = "range") - stepping interval for values that can be selected with the slider. Must be a numeric vector with one value for each slider in the input block.

  • min, max (only for type = "range") - minimal and maximal values that can be selected with the slider. Must be a numeric vector with one value for each slider in the input block.

  • fontSize - changes font size of the labels. The default size is 17.

  • nrows - number of rows in the table of input elements. By default is defined by the number of elements.

  • ncols - number of columns of input elements. The default value is 1.

Interactivity settings

  • on_click, on_change - a function, to be called when user clicks on a button, enters text in a text field or moves a slider. The two properties are complete synonyms and can replace one another.

Global chart settings

  • title - title of the input block.

  • width - width of the chart in pixels. By default, width will be set to fit the content. If width is defined and it's smaller than content's width, scrolling will be possible.

  • heigth - height of the chart in pixels. By default, height will be set to fit the content. If height is defined and it's smaller than content's height, scrolling will be possible.

  • paddings - padding sizes in pixels. Must be a list with all the following fields: "top", "bottom", "left", "right".

Examples

Run this code
if (FALSE) lc_input(type = "checkbox", labels = paste0("el", 1:5), on_click = function(value) print(value),
value = TRUE)
lc_input(type = "radio", labels = paste0("el", 1:5), on_click = function(value) print(value),
         value = 1)
lc_input(type = "text", labels = paste0("el", 1:5), on_click = function(value) print(value),
         value = c("a", "b", "c", "e", "d"))
lc_input(type = "range", labels = paste0("el", 1:5), on_click = function(value) print(value),
         value = 10, max = c(10, 20, 30, 40, 50), step = c(0.5, 0.1, 1, 5, 25))
lc_input(type = "button", labels = paste0("el", 1:5), on_click = function(value) print(value))

Run the code above in your browser using DataLab