【问题标题】:Addressing multiple inputs in shiny处理闪亮的多个输入
【发布时间】:2016-10-14 13:45:36
【问题描述】:

我正在构建一个相对复杂的应用程序,其中我有动态数量的输入,标题为: d1, d2 .. dn。有一次我想尝试同时处理多个输入:

input[[grep(pattern="d+[[:digit:]]",input)]]

这当然会导致错误:

Must use single string to index into reactivevalues

所以我想知道是否有人知道一种优雅的方式来做这样的事情?

【问题讨论】:

    标签: r regex shiny


    【解决方案1】:

    您可以在输入中使用名称:

    grep(pattern = "d+[[:digit:]]", x = names(input), value = TRUE)
    

    一个工作示例:

    library("shiny")
    ui <- fluidPage(
      fluidRow(
        column(
          width = 6,
          lapply(
            X = 1:6,
            FUN = function(i) {
              sliderInput(inputId = paste0("d", i), label = i, min = 0, max = 10, value = i)
            }
          )
        ),
        column(
          width = 6,
          verbatimTextOutput(outputId = "test")
        )
      )
    )
    server <- function(input, output){
      output$test <- renderPrint({
        sapply(grep(pattern = "d+[[:digit:]]", x = names(input), value = TRUE), function(x) input[[x]])
      })
    }
    shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 是否有可能得到名字背后的实际值?
    • 是的,查看示例
    • 只有一个问题 - 我如何在 observeEvent 中处理多个输入?
    • 我目前卡在 observeEvent(c(input$d1,input$d2,input$d3),{})
    • 您可以使用:observeEvent(lapply(grep(pattern = "d+[[:digit:]]", x = names(input), value = TRUE), function(x) input[[x]]), {})
    猜你喜欢
    • 2016-02-21
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    相关资源
    最近更新 更多