我想从服务器扩展一个闪亮的应用程序中的 bslib 卡。这是一个最小的例子:
library(shiny)
library(bslib)
ui <- bslib::page_fluid(
actionButton("go", "GO"),
bslib::card(
h1("Hello"),
full_screen = TRUE
)
)
server <- function(input, output, session){
observe({
# some code to expand the card
}) |>
bindEvent(input$go)
}
shinyApp(ui, server)
session$sendCustomMessage
和一个模拟单击“展开”按钮的处理程序:
library(shiny)
library(bslib)
ui <- bslib::page_fluid(
tags$head(tags$script(HTML(
"Shiny.addCustomMessageHandler('expand',",
" function(message) {",
" $('#' + message.id + ' > bslib-tooltip > button').click();",
" }",
");"))),
actionButton("go", "GO"),
bslib::card(
id = "my_card",
h1("Hello"),
full_screen = TRUE
)
)
server <- function(input, output, session){
observeEvent(input$go, {
session$sendCustomMessage(type = 'expand', message = list(id = "my_card"))
})
}
shinyApp(ui, server)