How to create a working directory for each user in Shiny app?

Hi,

Setting the working directory is likely not going to work like that in Shiny. I suggest you generate a folder based off the user's session token, which is generated when a user connects to a Shiny app and located in the session variable.

library(shiny)

ui <- fluidPage(
  
)

server <- function(input, output, session) {
  
  dir.create(session$token)
  file.create(paste0(session$token, "/userFile.txt"))
  
}

shinyApp(ui, server)

Once you created the directory, you can save any file in that one using again the token which is the name of the base folder for that user. You should remember to erase the folder after the task finished, or you will have a lot of folders soon.

Why do you need to store user specific files anyway?

Hope this helps,
PJ