简体   繁体   English

如何从ShinyFiles上传RData

[英]How to upload RData from ShinyFiles

I want to upload RData files using ShinyFiles, but I don´t know how to do it. 我想使用ShinyFiles上传RData文件,但是我不知道该怎么做。

This is not working for me: 这对我不起作用:

library(shiny)
library(shinydashboard)
library(shinyFiles)



# Define UI for application that draws a histogram
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    shinyFilesButton('files', label='File select', title='Please select a file', multiple=FALSE),

    verbatimTextOutput("txt")
  )
)



# Define server logic required to draw a histogram
server <- function(input, output) {

  shinyFileChoose(input, 'files', root=c(root='/'), filetypes=c('', 'RData'))
  output$txt <- renderPrint(
    ls(parseFilePaths(roots= "/",selection = input$files))
  )



}

# Run the application 
shinyApp(ui = ui, server = server)

What´s wrong? 怎么了? I really dont understand how parseFilesPaths really works, because it get the route to the file, but I can not make it working. 我真的不明白parseFilesPaths是如何工作的,因为它获取到文件的路由,但是我无法使其工作。 Also I have tried with 我也尝试过

files< - load(parseFilePaths(roots= "/",selection = input$files)$type)

But it also didnt work... 但这也没有用...

Thansk!! 谢谢!

I have solved it. 我已经解决了 Here the solution (hope this will be helpfull for others) 这里的解决方案(希望这对其他人有帮助)

# Define UI for application that draws a histogram
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    shinyFilesButton('files', 'File select', 'Please select a file', FALSE),
    verbatimTextOutput('filepaths')
  )
)



# Define server logic required to draw a histogram
server <- function(input, output) {
  roots = c(wd='/home/developer/')


  reactivity <- reactive({ 
    shinyFileChoose(input, 'files', roots=roots, filetypes=c('', 'RData'))
    ruta <- parseFilePaths(roots, input$files)$datapath
    load(ruta)
    return(parseFilePaths(roots, input$files))
    })

  output$filepaths <- renderPrint({

 reactivity()

    })



}

# Run the application 
shinyApp(ui = ui, server = server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM