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

jsCalls

mergeCalls(...)

Format

An object of class list of length 6.

Arguments

...

jsCalls to be merged.

Examples

conditionalJS(
  shiny::tags$button("Hello"),
  "input.value > 0",
  jsCalls$show()
)
#> <button data-call-if="input.value &gt; 0" data-call-if-true="$(this).removeClass(&#39;sg_hidden&#39;);" data-call-if-false="$(this).addClass(&#39;sg_hidden&#39;);" data-call-once="true" data-ns-prefix="">Hello</button>
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)
}