Package 'emberui'

Title: Interactive Inputs for Ember Notebooks
Description: Sliders, number boxes, checkboxes, text boxes, dropdowns and radio buttons for Ember notebooks, alone or several together as one input. In Ember, an input assigned to a name becomes a widget, and moving it reruns the cells that read the name. Anywhere else (Rscript, the R console, knitr) each function checks its arguments and returns its default value.
Authors: Jonathan Chen [aut, cre]
Maintainer: Jonathan Chen <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9000
Built: 2026-10-24 18:20:04 UTC
Source: https://github.com/jowch/Ember

Help Index


Interactive inputs

Description

Each function returns a plain value: a number, TRUE/FALSE, a string, an element of choices, or for input_list() a named list of its inputs' values. In an Ember notebook, an input assigned to a name at the top of a cell (n <- input_slider(1, 10)) is shown as a widget, and moving it sets n and reruns the cells that read n. Anywhere else (Rscript, the R console, knitr), and for any other call, the function checks its arguments and returns its default.

Usage

input_slider(min, max, value = min, step = NULL, label = NULL)
input_number(value = 0, min = NA, max = NA, step = NA, label = NULL)
input_checkbox(value = FALSE, label = NULL)
input_text(value = "", label = NULL)
input_select(choices, selected = choices[[1]], multiple = FALSE, label = NULL)
input_radio(choices, selected = choices[[1]], label = NULL)
input_list(...)

Arguments

min, max

The range of the input. For input_number(), NA means no limit.

value

The default value. A number keeps its type: input_slider(1L, 10L) returns an integer.

step

The step between the widget's values, or NULL or NA for none. A slider's values are its steps, counted from min: a value between them, the default included, is an error. A number box takes its step as a hint and allows a value between steps.

label

The text shown with the widget. By default, the name the input is assigned to.

choices

A vector or list. The value is an element itself, not its position. Names, if present, are what the widget shows. Numbers match by value, as with %in%: selected = 5 picks the choice 5L.

selected

The default choice: an element of choices, or with multiple = TRUE, a vector (or list) of them.

multiple

Whether several choices can be picked.

...

For input_list(): named input calls, such as n = input_slider(1, 10). Each must be an input call itself.

Details

Inside Ember, the input is bound to a name only when the call is the whole right-hand side of a top-level assignment and nothing else in the cell reads or redefines that name. Only the input on the cell's last line is shown as a widget, as the cell's output; any other input shows as a line below the cell with its value, saying how to fix it. Moving an input doesn't rerun its own cell.

To move several inputs from one cell, combine them with input_list(): p <- input_list(n = input_slider(1, 10), method = input_select(c("a", "b"))) shows both widgets together, and other cells read p$n and p$method. Moving either sets p.

Input values aren't saved with the notebook: it opens with every input at its default, the value Rscript uses. To keep a value, change the default in the code.

Value

The input's value. Outside Ember, the default.

Examples

n <- input_slider(10, 500, value = 100, step = 10)
method <- input_select(c(Pearson = "pearson", Spearman = "spearman"))
show <- input_checkbox(TRUE, label = "Show points")
title <- input_text("Results")
p <- input_list(n = input_slider(1, 10), method = input_select(c("a", "b")))
n
method
p$n