如何创建查找

时间:2017-11-24 02:37:59

标签: r shiny lookup-tables

我目前有一个Shiny应用程序,你可以上传一个csv文件,它会 告诉你数据。 我想添加一个搜索栏,您可以在其中搜索特定的行 三个变量。 然后我想要我搜索过的这些行然后选择形成一个 新的可下载的csv。 这可能吗?

x

Even if I simply select 3 rows as done here, all 15 rows are shown in the downloaded file as shown in the next picture

The downloaded file simply produces all data rather than just the ones I am filtering for

1 个答案:

答案 0 :(得分:0)

下面的代码将解决问题

library(shiny)
library(shinyjs)
library(DT)
library(dplyr)
library(data.table)
#I don't need all these packages just yet but I will use them as I carry on the project hopefully
ui = fluidPage(
  fileInput("Rams","Upload complete list of Rams", accept=".csv"),  
  br(),
  DT::dataTableOutput("Rams1"),downloadButton(outputId = "download_filtered",
                                              label = "Download Filtered Data")
)

server = function(input, output, session) {

  datasetInput <- reactive({
    infile <- input$Rams
    if(is.null(infile))
      return(NULL)
    read.csv(infile$datapath, header = TRUE)
  })

  output$Rams1 = DT::renderDataTable(datatable(datasetInput() ,filter = "top"),
  server = FALSE)


  output$download_filtered <- 
    downloadHandler(
      filename = "Filtered Data.csv",
      content = function(file){
        write.csv(datasetInput()[input[["Rams1_rows_all"]], ],
                  file)
      })

}

shinyApp(ui=ui, server=server)

enter image description here

enter image description here