View source: R/widget-factory.R
| widget | R Documentation |
widget() creates a new widget type and returns its constructor. All
behaviour is given as plain functions that receive the widget as their
first argument, self.
widget(
name,
state = list(),
render = NULL,
compose = NULL,
bindings = list(),
actions = list(),
on = list(),
methods = list(),
style = NULL,
focusable = FALSE,
inherit = Widget
)
name |
Type name (used by type selectors, e.g. |
state |
A named list of state fields. Values created with
|
render |
|
compose |
|
bindings |
A list of |
actions |
A named list of |
on |
A named list of event handlers |
methods |
A named list of extra methods |
style |
Default |
focusable |
Can widgets of this type receive focus? |
inherit |
Parent class: Widget, Vertical or Horizontal. |
A constructor function
function(..., id = NULL, classes = NULL, style = NULL, disabled = FALSE).
Named arguments in ... set initial state values; unnamed arguments are
child widgets.
Counter <- widget(
"Counter",
state = list(count = reactive(0L)),
render = function(self) sprintf("Count: %d", self$count),
bindings = list(bind("up", "increment"), bind("down", "decrement")),
actions = list(
increment = function(self) self$count <- self$count + 1L,
decrement = function(self) self$count <- self$count - 1L
),
focusable = TRUE
)
counter <- Counter(count = 5L)
counter$count
render_widget(counter, 12, 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.