gpt4 book ai didi

r - 基于用户选择的输入数量的条件面板

转载 作者:行者123 更新时间:2023-12-04 02:04:34 26 4
gpt4 key购买 nike

我正在尝试根据在 multiple = TRUE 的 selectInput 中选择的条目数来填充不同数量的字段。因此,如果从“numfields”输入中选择了 1 个条目,则会出现第一个 conditionalPanel,依此类推。我现在所拥有的显示了我希望在没有任何用户输入的情况下有条件的输入。

  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 = "count(input$numfields) >= 1",
textInput(inputId = "field1", label = "First One", value = "")
),
conditionalPanel(
condition = "count(input$numfields) >= 2",
textInput(inputId = "field2", label = "Second One", value = "")
),
conditionalPanel(
condition = "count(input$numfields) >= 3",
textInput(inputId = "field3", label = "Third One", value = "")
)
)
)

server <- function(input, output, session)
{}

shinyApp(ui=ui, server=server)

此外,在相关说明中,Shiny 自动默认为没有为 multiple = TRUE 的 selectInput 字段选择条目。有没有办法让它像 multiple = FALSE 时那样选择第一个条目?

感谢任何帮助,谢谢。

最佳答案

这是通过服务器的另一种解决方案。显而易见的解决方案是 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)

关于r - 基于用户选择的输入数量的条件面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44418241/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com