简体   繁体   English

R - shiny radioGroupButtons 在查看器中无法很好地呈现

[英]R - shiny radioGroupButtons not rendering well in viewer

I used some of the logic from here How to put shiny radioGroupButtons into columns and can't seem to get the layout to look correctly in the viewer pane.我使用了此处的一些逻辑How to put shiny radioGroupButtons into columns并且似乎无法使布局在查看器窗格中正确显示。 The buttons look fine in Chrome.这些按钮在 Chrome 中看起来不错。 I'm not sure how to fix it.我不知道如何解决它。

在此处输入图像描述

library(shiny)
library(shinyWidgets)
library(stringr)

# need radioGroupButtons to be in columns
my_css <-
  ".btn {
    padding:2px;
    width: 250px;
    height: 60px;
  }

  .btn-group, .btn-group-vertical {
    column-count: 3;
    column-width: 0;
  }"

# if you're not familiar with local() it just prevents clutter in the global env
# by just returning the last object
button_options <- local({
  first_3 <- "^([^ ]* ){3}"
  sample_sentences <- sentences[1:9]
  paste(
    "<big>", str_extract(sample_sentences, first_3),
    "</big><br>", str_remove(sample_sentences, first_3)
  )
})
  
# build gadget
ui <- fluidPage(
  tags$head(tags$style(HTML(my_css))),
  shinyWidgets::radioGroupButtons(
    inputId = "buttons",
    label = NULL,
    choices = button_options
  )  
)

server <- function(input, output) {}

runGadget(shinyApp(ui, server))

The fix was using a CSS grid instead:该修复程序使用 CSS 网格代替:

.btn-group-container-sw {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }

.radiobtn {
    width: 100%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM