微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用shinyFiles从我的服务器端或本地机器上传数据集?

如何解决如何使用shinyFiles从我的服务器端或本地机器上传数据集?

我想从我的服务器端(指向服务器端的链接)或本地机器上传文件,然后数据集将被处理以进行一些可视化。我这里的简单代码有什么办法可以更新为从我的服务器端或本地机器上传文件。目前我的代码只能从本地机器上传,如下所示:

UI.R

fluidPage(
          
          titlePanel("Data browser"),sidebarLayout(
            
            Box(width = 12,br(),# radioButtons("filetype","Select file type",choices=c("csv file","xlsx file","xls file")),fileInput("file","Choose file to upload..",accept = c("text/csv","text/comma-separated-values,text/plain",".csv",".xlsx",".xls"))
                
            ),mainPanel(
              width = 12,uIoUtput("data_browsing")
            )
          )
          
        )

server.R


 ############################################################
  ############## Datasets in and out #########################
  ############################################################
  
  # loading data
  data <- eventReactive(input$file,{
    extension <- tools::file_ext(input$file$name)
    filepath <- input$file$datapath
    switch(extension,csv = read.csv(filepath),xls = readxl::read_xls(filepath),xlsx = readxl::read_xlsx(filepath)
    )
  })
  
  #get data from data browser
  data_input <- reactive({
    data()
  })
  
  # info of the file
  # output$about_file<-renderTable({
  #   summary(input$file)  #input$file1
  # })
  output$about_file <- renderPrint({str(data())})
  
  # to display data
  output$display <- renderDataTable({
    dataset = data()},filter = 'top',escape = FALSE,options = list(pageLength = 10,scrollX='500px',autoWidth = TRUE))
  
  # passing to UI finally
  output$data_browsing<-renderUI({
    if(is.null(data())){
      
    }else if(length(data())==1){
      #h4(br(),"Mismatch in formats of file selected and uploaded!",style = "font-style: italic;font-weight: bold;color: red;text-align: center;")
      h4(br(),style = "color:red")
    }else{
      tabsetPanel(tabPanel("Data browse",dataTableOutput("display")),tabPanel("Data Summary",verbatimtextoutput("about_file")))
    }})
  
  # End of Loading data
  
  ############################################################
  #################  End of datasets part ####################
  ############################################################

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。