ThinkR-open / ThinkR-open/golem

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

Open
#693 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
R
Stars
945
Forks
136
PR merge metrics
No merged PRs in 30d

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}.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing add_resource_path in app_ui.R and the related addResourcePath behavior in httpuv, comparing it with bundle_resources and the manifest.webmanifest example. Reproduce the PWA resource-serving case, then verify that / or . prefixes can expose files at the app root without breaking existing www paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.