jsCalls: List of JavaScript calls for 'conditionalJS'

jsCallsR Documentation

List of JavaScript calls for 'conditionalJS'

Description

Each 'jsCalls' function can be used as a 'jsCall' argument of conditionalJS. See js_calls for possible options.

You can apply multiple calls with using 'mergeCalls'.

Usage

jsCalls

mergeCalls(...)

Arguments

...

jsCalls to be merged.

Format

An object of class list of length 6.

Examples

conditionalJS(
  shiny::tags$button("Hello"),
  "input.value > 0",
  jsCalls$show()
)
if (interactive()) {
  library(shiny)

  ui <- fluidPage(
    tags$head(
      tags$script(
        "var update_attr = function(message) {",
        "$('#' + message.id).attr(message.attribute, message.value);",
        "}",
        "Shiny.addCustomMessageHandler('update_attr', update_attr);"
      )
    ),
    sidebarLayout(
      sidebarPanel(
        selectInput("effect", "Animation type", choices = .cssEffects)
      ),
      mainPanel(
        conditionalJS(
          ui = plotOutput("cars"),
          condition = "input.effect != ''",
          jsCall = jsCalls$custom(true = runAnimation(effect = "bounce")),
          once = FALSE
        )
      )
    )
  )

  server <- function(input, output, session) {
    output$cars <- renderPlot({
      plot(mtcars$mpg, mtcars$qsec)
    })
    observeEvent(input$effect, {
      session$sendCustomMessage(
        "update_attr",
        list(id = "cars", attribute = "data-call-if-true", value = runAnimation(input$effect))
      )
    })
  }


  shinyApp(ui, server)
}


shinyGizmo documentation built on March 7, 2023, 7:31 p.m.