我正在尝试根据selectInput中选择的条目数来填充不同数量的字段,其中multiple = TRUE。因此,如果选择“numfields”输入中的1个条目,则会出现第一个conditionalPanel,依此类推。我现在所拥有的输入显示我希望在没有任何用户输入的条件下输入。
$response = getAmazonData("de", $parent);
Print_r($response);
此外,在相关说明中,Shiny自动默认为selectInput字段选择没有条目,其中multiple = TRUE。有没有办法让它选择第一个条目,就像多次= FALSE时一样?
感谢任何帮助,谢谢。
答案 0 :(得分:2)
这是通过服务器的另一种解决方案。
显而易见的解决方案是renderUI()
,但如果您想使用condtionalPanel()
:
a <- c("A","B","C")
Choices <- as.character(a)
ui <- fluidPage(
fluidRow(
selectInput(inputId = "numfields", label = "Select Entries", choices = Choices, multiple = TRUE, selectize = TRUE),
conditionalPanel(
condition = "output.check > 0",
textInput(inputId = "field1", label = "First One", value = "")
),
conditionalPanel(
condition = "output.check >= 2",
textInput(inputId = "field2", label = "Second One", value = "")
),
conditionalPanel(
condition = "output.check >= 3",
textInput(inputId = "field3", label = "Third One", value = "")
)
)
)
server <- function(input, output, session){
output$check <- reactive({
length(input$numfields)
})
outputOptions(output, 'check', suspendWhenHidden=FALSE)
}
shinyApp(ui=ui, server=server)
答案 1 :(得分:1)
您可以使用selectInput()
参数在selected =
中设置默认选择:
selectInput(inputId = "numfields",
label = "Select Entries",
choices = Choices,
multiple = TRUE,
selectize = TRUE,
selected = 'A')
condition =
中的conditionalPanel()
参数将文字解释为JS
而不是R
。
检查输入&#39;计数&#39;你应该使用input.numfields.length
:
conditionalPanel(
condition = "input.numfields.length >= 1",
textInput(inputId = "field1", label = "First One", value = "")
)
完整ui
下方
ui <- fluidPage(
fluidRow(
selectInput(inputId = "numfields",
label = "Select Entries",
choices = Choices,
multiple = TRUE,
selectize = TRUE,
selected = 'A'),
conditionalPanel(
condition = "input.numfields.length >= 1",
textInput(inputId = "field1", label = "First One", value = "")
),
conditionalPanel(
condition = "input.numfields.length >= 2",
textInput(inputId = "field2", label = "Second One", value = "")
),
conditionalPanel(
condition = "input.numfields.length >= 3",
textInput(inputId = "field3", label = "Third One", value = "")
)
)
)