【问题标题】:Extract value/name from r Markdown selectInput (drop down menu)从 r Markdown selectInput 中提取值/名称(下拉菜单)
【发布时间】:2026-01-05 02:50:01
【问题描述】:

如何从 r markdown selectInput 下拉菜单中提取选定的选项?我的网页上有响应式输入,如下所示:

aggdata <- data.frame(
  "Experiment" = c("One","Two","Three"),
  "AnythingElse" = c(1,2,3)
)

selectInput("Experiment1","Choose the first experiment",
        choices = unique(aggdata$Experiment),
        selected = unique(aggdata$Experiment)[1])
reactiveData <- reactive(as.data.frame(subset(aggdata, Experiment == input$Experiment1)))
firstExperiment_aggData <- reactive(reactiveData())

我想在文本的某个地方响应式地写下用户的选择。你碰巧知道吗,我该怎么做。非常感谢。

【问题讨论】:

    标签: r r-markdown shiny shinydashboard


    【解决方案1】:

    就 Shiny 而言,您可以从这个开始。这对你有帮助吗?

    library(shiny)
    
    aggdata <- data.frame(
      "Experiment" = c("One","Two","Three"),
      "AnythingElse" = c(1,2,3)
    )
    
    ui <- shinyUI(
      fluidPage(
        selectInput("Experiment1","Choose the first experiment",
                    choices = unique(aggdata$Experiment),
                    selected = unique(aggdata$Experiment)[1]),
        tableOutput("table1")
      )
    )
    
    server <- shinyServer(function(input, output, session) {
      reactiveData <- reactive({
        return(as.data.frame(subset(aggdata, Experiment == input$Experiment1)))  
        })
      output$table1 <- renderTable({
        return( reactiveData() )
      })
    })
    
    shinyApp(ui = ui, server = server)
    

    【讨论】: