rshinypinsposit-connect

Downloading RData file from pin to working directory


Pins is a great R package. It works seamlessly with Azure, Connect and other services.

I have difficulty downloading the RData file from a Posit Connect pin. None of my solutions in the following example are working. Any thoughts on how to fix this?

library(rsconnect)

board <- board_connect()

data("mtcars")
data("iris")
data("airquality")

# Save Environment as RData
save.image("ShinyApp_input_data.RData", compress = TRUE)

## Upload RData
board %>% pin_upload(name = "ShinyApp_input_data", paths = "ShinyApp_input_data.RData")

# Download/load RData
path <- board %>% pin_download(name = "ShinyApp_input_data")
load(path)

# My attempts to download RData to working directory
board %>% pin_download(name = "ShinyApp_input_data", local_path = "ShinyApp_input_data.RData", overwrite = TRUE)
board %>% pin_get(name = "ShinyApp_input_data", local_path = "ShinyApp_input_data.RData", overwrite = TRUE)
board %>% pin_read(name = "ShinyApp_input_data", local_path = "ShinyApp_input_data.RData", overwrite = TRUE)
board %>% pin_fetch(name = "ShinyApp_input_data", local_path = "ShinyApp_input_data.RData", overwrite = TRUE)

PS: In a ShinyApp, it is possible to use ShinyApp_input_data.RData as a default option and download new data from pin only if it has been updated. In that case, download the updated data from pin and replace the local RData file in the project directory.

Your time and help is much appreciated.


Solution

  • Thanks to Julia Silge for her response on GitHub. https://github.com/rstudio/pins-r/issues/757

    Here is her working solution:

    library(pins)
    board <- board_connect()
    #> Connecting to Posit Connect 2023.05.0 at <https://colorado.posit.co/rsc>
    data("mtcars")
    data("iris")
    data("airquality")
    save.image("test-rdata-pin.RData", compress = TRUE)
    board |> pin_upload("test-rdata-env", paths = "test-rdata-pin.RData")
    

    And then in a new session I can read that pin and the objects in the environment are there:

    library(pins)
    board <- board_connect()
    #> Connecting to Posit Connect 2023.05.0 at <https://colorado.posit.co/rsc>
    board |> pin_download(name = "julia.silge/test-rdata-env") |> load()
    ls()
    #> [1] "airquality" "board"      "iris"       "mtcars"
    

    To copy the file into working directory

    path <- pin_download(name = "julia.silge/test-rdata-env")
    file_copy(path, getwd(), overwrite = TRUE)