简体   繁体   English

R闪亮的输入小部件

[英]R shiny input widget

What kind of Shiny input widget can I use to implement a selector as in the picture?我可以使用什么样的 Shiny 输入小部件来实现如图所示的选择器? Is it an action button used?是否使用了操作按钮?

在此处输入图片说明

This is most probably a radioButtons element styled with CSS.这很可能是一个带有 CSS 样式的 radioButtons 元素。 Here is an example how to apply this kind of formatting to radio buttons: https://stackoverflow.com/a/4642152/14327549以下是如何将这种格式应用于单选按钮的示例: https : //stackoverflow.com/a/4642152/14327549

With package shinyWidgets and a bit of CSS you can achieve the same result:使用包ShinyWidgets和一些 CSS,您可以获得相同的结果:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$h1("Active background color for radioGroupButtons"),
  
  tags$style(
    ".btn-custom.active, .btn-custom:active, .btn-custom:focus, .btn-custom:hover {
      background: #4B088A !important;
      color: #FFF !important;
    }",
    ".btn-custom {border-color: #4B088A; color: #4B088A; background: #FFF;}"
  ),
  
  radioGroupButtons(
    inputId = "somevalue",
    label = NULL,
    choices = c("All cases", "Active cases"),
    status = "custom"
  ),
  verbatimTextOutput("value")
)
server <- function(input, output) {
  
  output$value <- renderPrint({ input$somevalue })
  
}
shinyApp(ui, server)

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

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