create a drop-down selector to choose a single item which is a listing of CSV files then load and output the selection to a data table

I posted this on StackOverflow, but the title is incorrect.

[create a drop-down selector to choose a single item which is a listing of CSV files then load and output the selection to a data table](https://stackoverflow.com/questions/55818367/how-to-click-table-row-containing-csv-files-and-render-second-datatable

I could not create a drop-down selector to choose a single item which is a listing of CSV files then load and output the selection to a data table.

How would I link the Folder Select to populate a select input drop-down? Once selected, how would I load and output to a data table?

I have tried to create a drop-down input select box that is dependent on a previous input choice but could not figure out how to incorporate the example. https://sites.temple.edu/psmgis/2017/07/26/r-shiny-task-create-an-input-select-box-that-is-dependent-on-a-previous-input-choice/

## ui.R ##

library(shiny)
library(DT)

#REF:  https://stackoverflow.com/questions/39196743/interactive-directory-input-in-shiny-app-r
shinyUI(tagList(
    fluidPage(
        theme = "bootstrap.css",
        includeScript("./www/text.js"),
        titlePanel("Folder content upload"),
        fluidRow(column(
            12,
            wellPanel(
                tags$div(
                    class = "form-group shiny-input-container",
                    tags$div(tags$label("File input")),
                    tags$div(
                        tags$label(
                            "Choose folder",
                            class = "btn btn-primary",
                            tags$input(
                                id = "fileIn",
                                webkitdirectory = TRUE,
                                type = "file",
                                style = "display: none;",
                                onchange = "pressed()"
                            )
                        )
                    ),
                    tags$label("No folder choosen", id = "noFile"),
                    tags$div(
                        id = "fileIn_progress",
                        class = "progress progress-striped active shiny-file-input-progress",
                        tags$div(class = "progress-bar")
                    )
                ),
                verbatimTextOutput("results")
            )
        ),
        column(12, div(
            DT::dataTableOutput("tbl2")
        )))
    ),
    HTML(
        "<script type='text/javascript' src='getFolders.js'></script>"
## server.R ##

library(shiny)
library(ggplot2)
library(DT)
shinyServer(function(input, output, session) {
    df <- reactive({
        inFiles <- input$fileIn
        df <- data.frame()
        if (is.null(inFiles))
            return(NULL)
        for (i in seq_along(inFiles$datapath)) {
            tmp <- read.csv(inFiles$datapath[i], header = FALSE)
            df <- rbind(df, tmp)
        }
        df
    })
    output$tbl2 <- DT::renderDataTable({
        input$fileIn
    })
})

Hoping to incorporate:

htmlOutput("")

in the ui.R to populate the drop-down selector input.

Hoping to incorporate the output for that selector in the server.R, as shown in the URL example, or if there is a better solution.

End result: 1. Populate drop-down selector input from previously selected data. 2. List selected CSV file in a data table.

Does this discussion help by any chance? Select source data from directory members

1 Like

Yes, your response is perfect, by placing the URL of the specific CSV files to load in the dropdown. Thank you.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.