Choose folder or folder directory inside shiny app

╄→尐↘猪︶ㄣ 提交于 2020-01-23 01:34:12

问题


I have a problem using shiny. I want to choose the folder where all the files I want to use in my app are saved either 1) by setting the working directory to that folderpath or 2) by uploading all csv data inside this folder to my app for further processing. for 1) I found the shinyFiles package but it is very very slow -not due to my PC- as well as giving me the error:

Warning: Error in dir.create: invalid 'path' argument
Stack trace (innermost first):
    59: dir.create
    58: dirCreate
    57: observerFunc
     2: runApp
     1: shinyFilesExample

when I selected a folder and the create folder button becomes clickable and I am putting a name of the new folder into it and clicking on the "+" beneath that panel. Anybody knows why? Despite that this method works but is very very slow. code below:

library(shiny)
library(shinyFiles)

ui<-fluidPage(sidebarLayout(

  sidebarPanel(
    shinyDirButton("dir", "Chose directory", "Upload")
  ),

  mainPanel(
    h4("output$dir"),
    verbatimTextOutput("dir"), br()

  )

))


server <- function(input,output,session){

  # dir
  shinyDirChoose(input, 'dir', roots = getVolumes())
  dir <- reactive(input$dir)
  output$dir <- renderPrint(dir())




}
shinyApp(ui = ui, server = server)

Is there another option? Maybe to upload all csv data via the fileInput function? Or another way? It should not work only locally but on a server so choose.dir might be not the right way. Many thanks


回答1:


so far, shinyfiles is the only way to input folders, as far as I know. It cannot work on a server, because browsers are not allowed to select folders (for security reasons).

The zipping way might be the only way to go if you want it to be working on a server (but I have no clue if it can actually be done)




回答2:


The funktion getwd() gets your current working directory.

server <- function(input,output,session){

  # dir
  shinyDirChoose(input, 'dir', roots = c(name=getwd()))
  dir <- reactive(input$dir)
  output$dir <- renderPrint(dir())
}


来源:https://stackoverflow.com/questions/43263867/choose-folder-or-folder-directory-inside-shiny-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!