简体   繁体   English

checkboxGroupButton - Select 一次一个

[英]checkboxGroupButton - Select one at a time

I'm trying to create a radiobutton in the style of the checkboxGroupButton() in R shiny.我正在尝试以 R shiny 中的 checkboxGroupButton() 样式创建单选按钮。

I want to recreate this example with the same button aesthetics, but only allow the user to select one input at a time.我想用相同的按钮美学重新创建这个例子,但一次只允许用户 select 一个输入。

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$h1("checkboxGroupButtons examples"),
  
  checkboxGroupButtons(
    inputId = "somevalue1",
    label = "Make a choice: ",
    choices = c("A", "B", "C")
  ),
  verbatimTextOutput("value1")
)
  
 

server <- function(input, output) {
  
  output$value1 <- renderPrint({ input$somevalue1 })

  
}

if (interactive())
  shinyApp(ui, server)

Thanks!谢谢!

To create a radiobutton with the same button aesthetics as the checkboxGroupButton() function in R shiny, you can use the radioButtons() function. This function allows you to create a group of radio buttons that the user can select from, but only allows the user to select one option at a time.要创建与 R shiny 中的 checkboxGroupButton() function 具有相同按钮美学的单选按钮,您可以使用 radioButtons() function。此 function 允许您创建一组单选按钮,用户只能从 8181274用户一次选择一个选项 select。

So this means it would look something like this:所以这意味着它看起来像这样:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$h1("Radiobutton examples"),
  
  radioButtons(
    inputId = "somevalue1",
    label = "Make a choice: ",
    choices = c("A", "B", "C")
  ),
  verbatimTextOutput("value1")
)

server <- function(input, output) {  
  output$value1 <- renderPrint({ input$somevalue1 })
}

if (interactive())
  shinyApp(ui, server)

Hope this helps: :)希望这可以帮助: :)

Or if you really want to use the checkboxes, then use the argument "selectize = TRUE", for instance, immediately bellow your argument "choices".或者,如果您真的想使用复选框,则使用参数“selectize = TRUE”,例如,立即在您的参数“choices”后面使用。

Figured it out - can simply be solved by replacing the checkboxGroupButtons() function with radioGroupButtons()想通了 - 可以简单地通过用radioGroupButtons()替换checkboxGroupButtons() function 来解决

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

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