从闪亮应用程序中的代码扩展 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)

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.