callback_context: In addition to event properties like n_clicks that change...

Description Usage Details Examples

View source: R/callbacks-advanced.R

Description

triggered: list of changed properties. This will be empty on initial load, unless an input prop got its value from another initial callback. After a user action it is a length-1 list, unless two properties of a single component update simultaneously, such as a value and a timestamp or event counter.

Usage

1

Details

inputs and states: allow you to access the callback params by id and prop instead of through the function arguments.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (interactive()) {
    dash_app() %>%
      set_layout(
        button('Button 1', id='btn1'),
        button('Button 2', id='btn2'),
        button('Button 3', id='btn3'),
        div(id='container')
      ) %>%
      add_callback(
        output("container", "children"),
        list(
          input("btn1", "n_clicks"),
          input("btn2", "n_clicks"),
          input("btn3", "n_clicks")
        ),
        function(btn1, btn2, btn3) {
          ctx <- callback_context()
          prevent_update(is.null(ctx))
          sprintf("Triggered: %s, btn1: %s, btn2: %s, btn3: %s",
                  ctx$triggered$prop_id, btn1, btn2, btn3)
        }
      ) %>%
      run_app()
  }

dash documentation built on Nov. 7, 2021, 9:06 a.m.