Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseDirPath provides wrong path if defaultPath and defaultRoot are set in shinyDirChoose #110

Open
lbusett opened this issue Nov 26, 2018 · 2 comments

Comments

@lbusett
Copy link

lbusett commented Nov 26, 2018

Hi,

I am working with shinyDirButton and shinyDirChoose to allow selection of a folder, starting from a specific default folder specified throgh defaultPath and defaultRoot. The problem is that when I then invoke parseDirPath to get the selected folder name, apparently the defaultPath value is ignored.

In practice, the returned path is

 `defaultRoot/name_of_folder`

while if I get the expected functionality right, it should be:

 `defaultRoot/defaultPath/name_of_folder`

Below you can find an example (not really reprex because it is related to my "paths"):

library(shiny)
library(shinyFiles)

ui <- {
  volumes <- c(main = "/home/lb/")
  shinyUI(fluidPage(
  
  titlePanel("Example"),
  shinyDirButton("savedir", "Save folder", "Save folder")
  ))
}
server <- shinyServer(function(input, output, session) {
  
  shinyDirChoose(input, "savedir",
                 roots=volumes,
                 defaultPath = "tmp", 
                 defaultRoot = "main",
                 session=session)
  
  observeEvent(input$savedir, {
     dirinfo <- parseDirPath(volumes, input$savedir)
     print(dirinfo)
  })
})

shinyApp(ui = ui, server = server)

If I run the example, I correctly get a "list of folders" starting from my "/home/lb/tmp" (although I see "main" on the top instead than "tmp" or "main/tmp"):

image

However, if I now select the "buttami" subfolder and click on "select", the path returned by

dirinfo <- parseDirPath(volumes, input$savedir)

is "/home/lb/buttami", while I would expect it to be "/home/lb/tmp/buttami"

Am I missing something/misunderstanding the functionality, here?

@vnijs
Copy link
Collaborator

vnijs commented Nov 26, 2018

@lbusett I see the issue. I'm not sure if there is a clean fix. My initial reaction is to simply get rid of defaultPath as things are likely to get messed up if you have multiple roots and you change away from the default root. If you want to default directory, why not just add to roots (see "Alternative" example below?

Also, I'm having some issues even selecting a directory if defaultPath is set in the "Original" example below.

@thomasp85, @Thercast, @AFriendlyRobot Thoughts?

Original issue:

library(shiny)
library(shinyFiles)

ui <- {
  volumes <- c(main = "/Users/vnijs/", Desktop = "/Users/vnijs/Desktop")
  shinyUI(fluidPage(
    
    titlePanel("Example"),
    shinyDirButton("savedir", "Save folder", "Save folder")
  ))
}
server <- shinyServer(function(input, output, session) {
  
  shinyDirChoose(input, "savedir",
                 roots=volumes,
                 defaultPath = "Desktop",
                 defaultRoot = "main",
                 session=session)
  
  observeEvent(input$savedir, {
    dirinfo <- parseDirPath(volumes, input$savedir)
    print(dirinfo)
  })
})

shinyApp(ui = ui, server = server)

Alternative that seems less problematic:

library(shiny)
library(shinyFiles)

ui <- {
  shinyUI(fluidPage(
    titlePanel("Example"),
    shinyDirButton("savedir", "Save folder", "Save folder")
  ))
}
server <- shinyServer(function(input, output, session) {
  
  shinyDirChoose(input, "savedir",
                 roots = c(main = "/Users/vnijs/", Desktop = "/Users/vnijs/Desktop"),
                 defaultRoot = "main",
                 session=session)
  
  observeEvent(input$savedir, {
    dirinfo <- parseDirPath(c(main = "/Users/vnijs/", Desktop = "/Users/vnijs/Desktop"), input$savedir)
    print(dirinfo)
  })
})

shinyApp(ui = ui, server = server)

@lbusett
Copy link
Author

lbusett commented Nov 26, 2018

@vnijs Thanks for looking into this.

The "use case" here is that I am developing a shinyApp that creates and relies on a "standardized" folder structure. Since I have multiple files selectors for different types of datasets, I findit useful to automatically set the folder chooser on the basis of the kind of dataset, by changing defaultPath.

However, I did not consider the possibility that the user could also change "root", making a mess with defaultroot. I recon that your suggestion of instead "adding" a new defaultRoot could be a better and safer solution (although it would not solve the issue we see when specifying both defaultPath and defaultRoot, leading to a "broken" path).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants