删除边框并在嵌套卡片之间进行切换

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

我有一些来自

card
的嵌套
bslib
,我想在它们之间切换。其中之一也有一个标题。我尝试使用
shiny::conditionalPanel
,但结果不好,留下了很大的空白。相反,我决定嵌套几张卡片,并给外面的一张
id
。这工作正常,但我真的很想删除外层的边框以及具有两个
card
card
的边框。

标头函数按预期工作,但我基本上已将其分配为

2x
与相同的
ID
。会这样吗?

library(bslib)
library(shinyWidgets)
library(shiny)

card_header <- card_header(
  "Setting",
  popover(
    bsicons::bs_icon("gear"),
    pickerInput(
      "choose_letter", "letter", inline = TRUE,
      choices = letters
)))


ui <- page_fillable(
  useShinyjs(),
  layout_sidebar(
    sidebar = sidebar(
      pickerInput("a", label = "Select", choices = c("A", "B"), options = list(size = 10)),
    ), card(id = "A", layout_columns(
      col_widths = c(12, 12, 12),
      row_heights = c(1, 2, 1),
      card(
        card_body(
          layout_column_wrap(
            width = 1/2,
            card("A"),
            card("A")
          )
        )
  ),
  card(card_header(card_header), "A"),
  card("A")
)),

card(id = "B", layout_columns(
  col_widths = c(12, 12, 12),
  row_heights = c(1, 2, 1),
  card(
    card_body(
      layout_column_wrap(
        width = 1/2,
        card("B"),
        card("B")
      )
    )
  ),
  card(card_header(card_header), "B"),
  card("B")
))

)
)

server <- function(input, output, session) {
  
  observeEvent(input$a, {
    print(input$a)
    lapply(c("A", "B"), function(letter) {
      toggle(id = letter, condition = letter %in% input$a)
    })
  }, ignoreNULL = FALSE)
  
  observeEvent(input$choose_letter,{
    
    print(input$choose_letter)

    updatePickerInput(session = session, "choose_letter", selected = input$choose_letter)
    
  }, ignoreNULL = TRUE, ignoreInit = TRUE)
  
}

shinyApp(ui, server)
r shiny bslib
1个回答
0
投票

要在嵌套卡片之间切换,请在侧边栏中添加操作按钮:

layout_sidebar(
    sidebar = sidebar(
      pickerInput("a", label = "Select", choices = c("A", "B"), options = list(size = 10)),
      actionButton("toggle","Toggle Cards")
    )

然后在您的服务器中:

observeEvent(input$toggle,{
    toggle("A")
    toggle("B")
  })

enter image description here

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