如何设置扩展bslib卡的事件?

问题描述 投票:0回答:1

我想从服务器扩展一个闪亮的应用程序中的 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)

r shiny bslib
1个回答
0
投票

您可以使用

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)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.