仅允许在checkboxGroupInput中使用一个tick

Raj*_*dra 7 r shiny

在这个闪亮的应用程序中,我需要允许用户只勾选一个复选框.反正有没有实现这个目标?

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"
    )
  )
))
Run Code Online (Sandbox Code Playgroud)

server.R

shinyServer(function(input, output) {

}
)
Run Code Online (Sandbox Code Playgroud)

Joh*_*aul 12

你可能应该使用radioButtons(),就像这样;

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

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

注意我在choices这个答案的部分修复了引号.感谢@Limbu指出错字.