2016-07-06 103 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)