ThinkR-open/golem

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

開放

#693 建立於 2021年6月21日

 (10 則留言) (1 個反應) (0 位負責人)R (137 個分叉)batch import
help wanted

倉庫指標

星標
 (938 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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

貢獻者指南