如何仅加载数据帧(而不是整个RData)?

时间:2017-08-21 19:13:33

标签: r shiny workspace

我想让我的用户只加载他们选择的数据框(而不是整个RData)。我怎么能这样做?

这些Shiny脚本用于加载数据框,但它也会加载整个RData。

server.R

function(input, output, session) {

    # Load RData
    observeEvent(input$load_RData, {
        load(input$RData_file$datapath, envir = .GlobalEnv)
    })

    # Display existing data frames in workspace

    output$df_exist <- renderPrint(
        if(input$load_RData==1) {
            cat(names(which(sapply(.GlobalEnv, is.data.frame))),sep="\n")
        }
    )

    # Load Data Frame
    observeEvent(input$load_df, {
        data <<- get(paste0("data_",input$str_name_load), envir = .GlobalEnv)
    })
}

ui.R

fluidPage(

        tabPanel(value='main',title=strong('Main'),

                    checkboxInput("check_load_df", label = strong("Load existing data frame"), value = FALSE),
                    conditionalPanel(
                        condition = ("input.check_load_df == 1"),
                        br(),
                        fileInput("RData_file", "RData name"),
                        br(),
                        actionButton("load_RData", "Load RData!"),
                        br(),
                        br(),
                        p(strong("List of data frames in the directory:")),
                        verbatimTextOutput('df_exist'),
                        br(),
                        textInput("df_name_load", "Dataframe"),
                        br(),
                        actionButton("load_df", "Load Dataframes!"),
                        br(),
                        br()
                    )
                )
)

0 个答案:

没有答案