Description Usage Arguments Details Examples
Constructs an input based on the type and values of provided data.
1 2 3 4 5 6 7 8 9 |
x |
Input data, which can be a vector, a one-column |
inputId |
The |
label |
Display label for the control, by default set to the value of |
selected_fraction |
Fraction of the data (between 0 and 1) to select upon creation of the widget. |
range |
Whether to create a widget that allows selecting a range rather than a single value. |
inline |
If TRUE, render the choices inline (i.e. horizontally) in |
... |
passed to the input widget creation functions. |
Widgets are chosen according to the class of x
:
boolean: checkboxInput
;
character, factor: checkboxGroupInput
if there are 20 or fewer unique values, selectInput
with multiple=TRUE
otherwise;
Date: dateInput
if range=FALSE
, dateRangeInput
if range=TRUE
;
numeric, POSIXct (date and time): sliderInput
with a single value if range=FALSE
or two if range=TRUE
.
In this last case, a simple heuristic is used to create good looking bounds for the slider, although the range selected by default is based on the actual data range. For example, if x
varies between 2.16 and 3.98 and selected_fraction=1
, the slider goes from 2 to 4 but the range initially selected would be [2.16, 3.98].
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ## Only run examples in interactive R sessions
if (interactive()) {
# simple example
set.seed(1)
autoInput(runif(10), "foo", "My automatic slider")
# create a data.frame with various types of data
n <- 40
d <- data.frame(
boolean=rep(c(TRUE, FALSE), times=n/2),
few_levels=letters[1:5],
many_levels=rep(letters,2)[1:n],
int=1:n,
num=runif(n, 0, 5),
large_num=runif(n, 0, 10^6),
small_num=runif(n, 0, 0.001),
date=Sys.Date()+1:n,
date_time=Sys.time()+1:n
)
str(d)
ui <- fluidPage(
fluidRow(
column(
6,
h2("Gallery"),
autoInput(d["boolean"]),
autoInput(d["few_levels"]),
autoInput(d["many_levels"]),
autoInput(d["int"]),
autoInput(d["num"]),
autoInput(d["large_num"]),
autoInput(d["small_num"]),
autoInput(d["date"]),
autoInput(d["date"], range=FALSE),
autoInput(d["date_time"]),
autoInput(d["date_time"], range=FALSE)
),
column(
6,
h2("Options"),
p("width=100%:"), autoInput(d["int"], width="100%", inline=TRUE),
p("selected_fraction=1:"), autoInput(d["int"], selected_fraction=1),
p("selected_fraction=0:"), autoInput(d["int"], selected_fraction=0),
p("selected_fraction=0.0001; when the variable is categorical,
the number of elements is rounded up to select at least one:"),
autoInput(d["few_levels"], selected_fraction=0.0001),
p("to select nothing, set selected_fraction to exactly 0:"),
autoInput(d["few_levels"], selected_fraction=0),
p("inline=FALSE:"), autoInput(d["few_levels"], inline=FALSE),
p("Change label and ticks aspect:"),
autoInput(d["small_num"], label=NULL),
autoInput(d["small_num"], sep=""),
autoInput(d["small_num"], ticks=FALSE),
p("etc.")
)
)
)
server <- function(input, output) {}
shinyApp(ui, server)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.