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

Can't pass the directory to addResourcePath #184

Open
nfuryn opened this issue Jun 12, 2023 · 1 comment
Open

Can't pass the directory to addResourcePath #184

nfuryn opened this issue Jun 12, 2023 · 1 comment

Comments

@nfuryn
Copy link

nfuryn commented Jun 12, 2023

ui <- fluidPage(
  shinyDirButton("directory", "Folder select", "Please select a folder")
)

server <- function(input, output, session) {
  library(shinyFiles)
  volumes <- c(Home = fs::path_home(), "R Installation" = R.home(), getVolumes()())
  shinyDirChoose(input, "directory", roots = volumes, session = session, restrictions = system.file(package = "base"), allowDirCreate = FALSE)
  dirname <- reactive({parseDirPath(volumes, input$directory)})
  observe({
    cat("\ninput$directory value:\n\n")
    print(input$directory)
  })
  output$directorypath <- renderPrint({
    if (is.integer(input$directory)) {
      cat("No directory has been selected (shinyDirChoose)")
    } else {
      parseDirPath(volumes, input$directory)
    }
  })
  dirpath <- ""
  
  observe({
    if(!is.null(dirname)){
      print(dirname())
      dirpath <- renderText(dirname())
    }
  })
  
  if (!is.null(dirpath) && dirpath != '') {
    addResourcePath("photos", dirpath)
  }
}

When in the app, the updated ResourcePath should allow me to show a local photo, but it doesn't. It shows a broken image. Here's the relevant part of the code:

observeEvent(input$addButton, {
    filtered_data <- filtered_data %>%
      filter(Photos == input$tag)
    if (nrow(filtered_data) > 0) {
      leafletProxy("map") %>%
        clearMarkers() %>%
        addMarkers(
          lng = filtered_data$GPSLongitude,
          lat = filtered_data$GPSLatitude,
          popup = paste0("<img src='photos/", filtered_data$filepath, "' width='300px' height='300px'>")})
        )
  })

However, if I use this in the code and manually enter my path, then it works:
addResourcePath("photos", (mypath))

@vnijs
Copy link
Collaborator

vnijs commented Jul 5, 2023

Can you use addResourcePath dynamically? I.e., add it while the app is already running?

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