ThinkR-open/golem

PWA compatibility: Allow addResourcePath to use / or . prefix to serve content at the app root

Ouverte

#693 ouverte le 21 juin 2021

 (10 commentaires) (1 réaction) (0 personne assignée)R (137 forks)batch import
help wanted

Métriques du dépôt

Stars
 (938 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

As discussed offline:

In a {golem} app, the app_ui.R contains some piece of code to make JS and CSS files in the www folder available to the app:

golem_add_external_resources <- function(){
  
  add_resource_path(
    'www', app_sys('app/www')
  )
 
  tags$head(
    favicon(),
    bundle_resources(
      path = app_sys('app/www'),
      app_title = 'golemReprex'
    ),
    tags$link(rel="manifest", href="manifest.webmanifest")
    #tags$script(src = "www/hello.js")
    # Add here other external resources
    # for example, you can add shinyalert::useShinyalert() 
  )
}

JS and CSS are recursively included in an htmlDependency by golem::bundle_resources such that we don't have to worry about it.

The addResourcePath is required because we run the app from a different folder of www, thereby making it visible from the server. This has however implications for any other files than JS and CSS (included in the dependency) such as any Progressive web app file like a manifest.webmanifest which has to be linked as /www/manifest.webmanifest. In a vanilla shiny apps, we don't need to prefix by www.

Here is a repo which presents a workaround for a progressive web app, I moved the app.R from ./R to inst/app (same as folder www) and inactivated the add_resource_path and bundle_resources (I don't want the service worker to go in an HTML dependency as it may cause registration issues):

https://github.com/DivadNojnarg/shinyMobileTest

Maybe we should have a look at addResourcePath and play a bit with {httpuv}.

Guide contributeur