Skip to contents

The two functions that allow to trigger a specific filtering panel action directly from Shiny server (.trigger_action) or application browser (.trigger_action_js) attached to a specific JS event, e.g. onclick.

Check Details section to see possible options.

Usage

.trigger_action(session, action, params = NULL)

.trigger_action_js(action, params = list(), ns = function(id) id)

Arguments

session

Shiny session object.

action

Id of the action.

params

List of parameters passed to specific action method.

ns

Namespace function (if used within Shiny modal).

Value

No return value (`.trigger_action` - sends message to the browser) or character string storing JS code for sending input value to Shiny server (`.trigger_action_js`).

Details

The list of possible actions:

  • update_filter - Calls `shinyCohortBuilder:::gui_update_filter` that triggers filter arguments update.

  • add_step - Calls `shinyCohortBuilder:::gui_add_step` that triggers adding a new filtering step (based on configuration of the previous one).

  • rm_step - Calls `shinyCohortBuilder:::gui_rm_step` used to remove a selected filtering step.,

  • clear_step - Calls `shinyCohortBuilder:::gui_clear_step` used to clear filters configuration in selected step.

  • update_step - Calls `shinyCohortBuilder:::gui_update_step` used to update filters and feedback plots for the specific filter GUI panel.

  • update_data_stats - Calls `shinyCohortBuilder:::gui_update_data_stats` that is called to update data statistics.

  • show_repro_code - Calls `shinyCohortBuilder:::gui_show_repro_code` that is used to show reproducible code.

  • run_step - Calls `shinyCohortBuilder:::gui_run_step` used to trigger specific step data calculation.

  • show_state - Calls `shinyCohortBuilder:::gui_show_state` that is used to show filtering panel state json.

  • input_state - Calls `shinyCohortBuilder:::gui_input_state` that is used to generate modal in which filtering panel state can be provided (as json).

  • restore_state - Calls `shinyCohortBuilder:::gui_restore_state` used for restoring filtering panel state based on provided json.

  • show_attrition - Calls `shinyCohortBuilder:::gui_show_attrition` a method used to show attrition data plot(s).

Both `.trigger_action` and `.trigger_action_js` methods are exported for advanced use only.

Examples

if (interactive()) {
  library(shiny)
  library(shinyCohortBuilder)

  shiny::addResourcePath(
    "shinyCohortBuilder",
    system.file("www", package = "shinyCohortBuilder")
  )
  ui <- fluidPage(
    tags$head(
      shiny::tags$script(type = "text/javascript", src = file.path("shinyCohortBuilder", "scb.js"))
    ),
    tags$button(
      "Trigger action from UI", class = "btn btn-default",
      onclick = .trigger_action_js("uiaction", params = list(a = 1))
    ),
    actionButton("send", "Trigger action from server")
  )

  server <- function(input, output, session) {
    observeEvent(input$send, {
      .trigger_action(session, "serveraction", params = list(a = 2))
    })
    observeEvent(input$action, {
      print(input$action)
    })
  }

  shinyApp(ui, server)
}