我想在 modalDialog (Shiny) 中创建 reactive() 数据

I want to create reactive() data within a modalDialog (Shiny)

我想在 modalDialog() 中创建一个 selectInput()。并基于 selectInput() 创建一个反应性数据集。但是我收到错误消息:

Warning: Error in : Problem with `filter()` input `..1`.
i Input `..1` is `name == input$selectName`.
x Input `..1` must be of size 87 or 1, not size 0.
  [No stack trace available]

而我可以在 renderText() 中反应性地创建 numericInput() 的输入。那里的区别在哪里?是否有可能在 modalDialog() 中创建反应数据?

library(shiny)
library(tidyverse)
data = starwars

ui = fluidPage(
  
  div(style = "margin-top: 50px; display: flex; justify-content: center;",
  actionButton(inputId = "openModal", label = "Open"))

)

server = function(input, output, session){
  
  
  
  observeEvent(input$openModal, {
    
    reactiveData = reactive({
      data %>% filter(name == input$selectName)
    })
    
    output$added = renderText({input$add})
    
    showModal(
      modalDialog(
        title = NULL, easyClose = T, size = "m", footer = modalButton("back"),
        tagList(
          
          div(selectInput(inputId = "selectName", label = NULL, choices = data$name)),
          div(numericInput(inputId = "add", label = NULL, value = 0)),
          div(reactiveData()%>%pull(height)),
          div(textOutput(outputId = "added"))
          
        ))
    )
    
  })
  
  
}

shinyApp(ui, server)

==替换为%in% in:

reactiveData = reactive({ data %>% filter(name == input$selectName)})

reactiveData = reactive({ data %>% filter(name %in% input$selectName)})

解释:来自 d.b 的回答

%in% 值匹配 和“returns 其(第一个)匹配位置的向量第二个参数中的第一个参数”(请参阅​​帮助('%in%'))这意味着您可以比较不同长度的向量,以查看一个向量的元素是否与另一个向量中的至少一个元素匹配。输出的长度将等于被比较的向量(第一个)的长度。

== 逻辑运算符 用于比较两个事物是否完全相等。如果向量长度相等,将比较元素 element-wise。如果不是,向量将被回收。输出的长度将等于较长向量的长度。