如何单击包含CSV文件的表行并呈现第二个数据表?

时间:2019-04-23 19:45:08

标签: shiny shinyapps

我无法创建一个下拉选择器来选择一个项目,该项目是CSV文件的列表,然后将所选内容加载并输出到数据表中。

如何链接“文件夹选择”以填充选择输入下拉菜单? 选择后,如何加载并输出到数据表?

我试图创建一个下拉输入选择框,该框取决于先前的输入选择,但无法弄清楚如何合并该示例。 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
    })
})

希望加入

htmlOutput("")
ui.R中的

填充下拉选择器输入。

希望将选择器的输出合并到server.R中,如URL示例所示,或者是否有更好的解决方案。

最终结果:  1.根据先前选择的数据填充下拉选择器输入。  2.在数据表中列出所选的CSV文件。

0 个答案:

没有答案