problems with workingDir in shiny server

I have set up a very basic shiny app and put it into /opt/shiny-server/samples/shiny/.
Shiny server tries and fails to write to my user directory.
Where does it come from?
It uses that wrong directory even when I set the workingDir explicitly with Sys.setenv(R_USER = "/opt/shiny-server/samples/shiny") or shiny::shinyOptions(workingDir = '/opt/shiny-server/samples/shiny').

My app.R:

library(shiny)
library(bslib)

ui <- navbarPage(
  theme = bs_theme(version = 5, bootswatch = 'cyborg'),
  title = "Shiny",
  id = "main-menu",
  tabPanel(
    "First tab",
    h1("First tab"),
    titlePanel("OFGD"),
    sidebarLayout(
      sidebarPanel(
        sliderInput("bins",
                    "Number of bins:",
                    min = 1,
                    max = 50,
                    value = 30)
      ),
      
      mainPanel(
        plotOutput("distPlot")
      )
    )
  ),
  tabPanel(
    "Second tab :-)",
    h1("Second tab")
  )
)

server <- function(input, output) {
  output$distPlot <- renderPlot({
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    hist(x, breaks = bins, col = 'darkgray', border = 'white',
         xlab = 'Waiting time to next eruption (in mins)',
         main = 'Histogram of waiting times')
  })
}

shinyApp(ui = ui, server = server)

Last lines in /var/log/shiny-server/shiny-shiny-20240902-083926-46831.log:

Warning in dir.create(cache_dir, recursive = TRUE) :
  cannot create dir '/share/rstudio-home/david/shiny/app_cache', reason 'Permission denied'
Warning in value[[3L]](cond) :
  Error using cache directory at '/share/rstudio-home/david/shiny/app_cache/sass'. Using temp dir instead.

This directory seems not to be set anywhere and still overrides every setting I try to give in the shiny app.
Also, I don't understand, where the sass comes from. I am not explicitly calling it in my code.

Can anyone help?

I think bslib::bs_theme() is what calls sass, that tries to cache. See for example here.

Shiny [...] will perform this compilation automatically when handed a bs_theme()

cache This can be a directory to use for the cache, a FileCache object created by sass_file_cache(), or FALSE or NULL for no caching.

Sass caching and precompilation
If Shiny Developer Mode is enabled (by setting options(shiny.devmode = TRUE) or calling shiny::devmode(TRUE)), both sass caching and bslib precompilation are disabled by default; that is, a call to bs_theme_dependencies(theme) expands to bs_theme_dependencies(theme, cache = F, precompiled = F)).

If I understand correctly, you can solve this by setting the option sass.cache or by creating a directory named app_cache/ that will be automatically used.

Also pinging this old question for backlinking.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.