trigger-action {shinyCohortBuilder}R Documentation

Trigger filtering panel action

Description

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).

Details

The list of possible actions:

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

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').

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)
}

[Package shinyCohortBuilder version 0.2.1 Index]