PWA compatibility: Allow addResourcePath to use / or . prefix to serve content at the app root
#693 创建于 2021年6月21日
仓库指标
- 星标
- (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}.