2016-07-06 91 views
1

在闪亮的情况下,我希望用户能够在文本框中为“性别”编写第三个值,如果即使只有“男性”和“女性”包含在“选择“矢量。闪亮的重叠小工具

ui <- fluidPage(
    selectInput("foo", label = "sex", choices = c("male","female"), selectize = T) 
) 

server <- function(input, output) {  
} 

shinyApp(ui = ui, server = server) 

我可以做一个额外的文本字段和“添加新选项”按钮(如其他问题中所建议的)。但是,我希望用户能够在原始文本框中正确输入新选项。

+1

有一个“其他”的选择,然后显示在同一个位置上的文本输入框。 –

+0

是的,这是一个好主意。我想直接在文本框中输入新的类别,但我想这样做并不是那样的! –

回答

0

我终于这个42以下的建议:

library(shiny) 

ui <- fluidPage(
    fixedRow(
    column(4, 
      conditionalPanel(
      condition = "input.sex != 'other'", 
      selectInput("sex", label = "sex", choices = c("male","female","other"), selectize = T) 
      ) 
    ) 
), 
    fixedRow(
    column(4, 
      conditionalPanel(
      condition = "input.sex == 'other'", 
      textInput("sex_o", "write sex") 
      ) 
    ) 
) 
) 


server <- function(input, output) { 
} 

shinyApp(ui = ui, server = server)