Appifyr offers three types of inputs: dropdown, text and number. Test
All input types share the arguments label
and width
. The label will be displayed next to the input on the form. The width argument accepts integer values between 1 and 12 (it’s using the bootstrap grid system). A value of 12 will make the input take an entire row. The default width is 4.
The inps
argument takes a list where every element is named corresponding to one of the arguments to your function. So, for a function my_function(x, y)
you must specify both x
and y
in the list, e.g. list(x = inp_text(), y = inp_text())
. The names must match exactly. Note that it is possible to pass anything to ...
.
The text input inp_text
is the most basic type of input.
appify("text_to_title", inps = list(plot_title = inp_text(width = 12)))
You can use the number input inp_number
type to restrict values to numbers.
appify("number_to_sample", inps = list(n = inp_number(from = 0, to = 10e9)))
Appifyr’s function inp_dropdown
accepts atomics, lists and datafarmes as arguments. Intrnally, appifyr always converts to a dataframe.
When given a vector as the first argument the keys will be equal to the values passed to the function.
appify("dropdown_to_filter",
inps = list(flower = inp_dropdown(unique(iris$Species))))
A list should be used when one deals with a fairly small number of levels and needs specific names for those. The format is intuitive: list(key1 = "value1", key2 = "value2")
.
flowers <- list(
Setosa = "setosa",
Versicolor = "versicolor",
Virginica = "virginica"
)
appify("dropdown_to_filter", inps = list(flower = inp_dropdown(flowers)))
The dataframe argument needs a specific format. There must be exactly two columns key
and value
. This type of passing the levels is most useful when one wants to create a large number of levels.
flowers <- data.frame(value = unique(iris$Species)) %>%
mutate(key = str_to_title(value))
appify("dropdown_to_filter", inps = list(flower = inp_dropdown(flowers)))