jsCalls.Rd
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(...)
An object of class list
of length 6.
jsCalls to be merged.
conditionalJS(
shiny::tags$button("Hello"),
"input.value > 0",
jsCalls$show()
)
#> <button data-call-if="input.value > 0" data-call-if-true="$(this).removeClass('sg_hidden');" data-call-if-false="$(this).addClass('sg_hidden');" 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)
}