【问题标题】:Allowing one tick only in checkboxGroupInput只允许在 checkboxGroupInput 中打勾
【发布时间】:2014-12-22 17:29:22
【问题描述】:

在这个闪亮的应用程序中,我只需要允许用户勾选一个复选框。有没有办法做到这一点?

ui.R

library(shiny)
shinyUI(fluidPage(
  titlePanel("abc"),
  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput("choice", "What will you like to see?",
                         choices=c("red","green")),
      conditionalPanel(
        condition = "input.choice == 'red'",
        sliderInput("slider1","slide",min=0,max=100,value=100,step=1,animate=TRUE)),
      conditionalPanel(
        condition="input.choice=='green'",
        selectInput("choice","Select", c("a","b","c")),
        sliderInput("slider2","slide",min=0,max=100,value=100,step=1,animate=TRUE))
      ),     
    mainPanel(
      "abc"
    )
  )
))

服务器.R

shinyServer(function(input, output) {

}
)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您可能应该改用radioButtons(),就像这样;

    radioButtons(inputId="choice", label="What would you like to see?", 
                   choices=c("red","green"))
    

    这将让用户只选择其中一个选项。

    注意我修复了此答案的 choices 部分中的引号。感谢@Limbu 指出错误。

    【讨论】:

      【解决方案2】:

      您忘记在每个选项周围加上引号,您将两个选项组合为一个选项

      radioButtons(inputId="choice", label="What would you like to see?", 
                     choices=c("red","green"))
      

      【讨论】:

      • 我不确定你的意思。有引号。
      猜你喜欢
      • 2020-09-09
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2018-03-03
      • 2017-01-04
      相关资源
      最近更新 更多