在这个闪亮的应用程序中,我需要允许用户只勾选一个复选框。反正有没有实现这个目标?
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"
)
)
))
server.R
shinyServer(function(input, output) {
}
)
答案 0 :(得分:12)
你可能应该使用radioButtons()
,就像这样;
radioButtons(inputId="choice", label="What would you like to see?",
choices=c("red","green"))
这将让用户只选择其中一个选项。
注意我修复了此答案的choices
部分中的引号。感谢@Limbu指出错字。
答案 1 :(得分:3)
您忘了在每个选项周围加上引号,您将两个选项分组为单个选项
radioButtons(inputId="choice", label="What would you like to see?",
choices=c("red","green"))