2016-10-05 29 views
0

如何从r markdown selectInput下拉菜单中提取选定的选项?我有我的网页类似下面的反应输入:从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()) 

而且我想某处写入文本被动,什么是用户的选择。你碰巧知道,我该怎么做。提前谢谢了。

回答

0

就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) 
+0

谢谢你,但实际上我使用r Markdown。我如何在Markdown中做到这一点? – martinkabe

+0

它记录在这里非常确切:http://rmarkdown.rstudio.com/authoring_shiny_advanced.html 而这里是另一个链接:http://rmarkdown.rstudio.com/authoring_shiny.html – nilsole

+0

非常感谢你! ! – martinkabe