devopifex / leprechaun Goto Github PK
View Code? Open in Web Editor NEW:four_leaf_clover: Code generator for lean and robust shiny applications
Home Page: https://leprechaun.opifex.org
License: GNU General Public License v2.0
:four_leaf_clover: Code generator for lean and robust shiny applications
Home Page: https://leprechaun.opifex.org
License: GNU General Public License v2.0
Hi John,
Thanks for your reply and solution in issues JohnCoene/packer#23 and #7. I finally had some time again to take a look at it again.
The ignoring of the index.js works!
However, I noticed that when not adding it to the ignore, it would still be ignored.
It turns out that not ignoring any assets results in all assets being ignored.
I looked into the problem and found the cause, it has to do with the regular expression that is created find ignored assets.
When the vector is empty, the regex becomes "$", this will make it so that all assets are matched and thus ignored.
I fixed it like this:
ignore_pat <- paste0(c("^", ignore), collapse = "|", sep ="$")
This will always add "^$" to the regular expression which should match nothing and thus ignore nothing.
Hi, and thanks for this nice package
There seems to be an inconsistency when running an app with devtools::document() ; devtools::load_all() ; run()
as described in your quick start guide and running from empty env after library(myapp)
.
Code to reproduce behavior and screenshot :
# make app as package
usethis::create_package("myapp")
leprechaun::scaffold()
# run it like in quick start from leprechaun doc
devtools::document()
devtools::load_all()
run()
#then install it
devtools::install()
from a new R session :
library(myapp)
run()
My sessionInfo :
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
locale:
[1] LC_CTYPE=fr_FR.UTF-8 LC_NUMERIC=C
[3] LC_TIME=fr_FR.UTF-8 LC_COLLATE=fr_FR.UTF-8
[5] LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=fr_FR.UTF-8
[7] LC_PAPER=fr_FR.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.2
If your package has an existing R/zzz.R
with an onload hook the content from scaffold overwrites this completely. Ideally it would add the new content to the onload hook if it already exists.
I'm trying to load a JS file containing an ESM module as a dependency using serveAssets(modules = "my_module.js")
. The function should create a script tag in the HTML head that looks like this <script src="[...]/my_module.js" type="module">
.
What actually gets added to the HTML-head is this:
<head>
...
<meta name="type" content="module">
<script src="[...]/my_module.js"></script>
...
</head>
As a result, the browser doesn't know it is is dealing with an ESM module, throws an error Uncaught SyntaxError: Unexpected token 'export'
when it encounters the mosule exports, and fails to load the module.
I've had a look at the template for assets.R
.
I think the error is happening here:
if(!is.null(modules)){
modules <- htmlDependency(
"#PKGNAME#-modules",
version = utils::packageVersion("#PKGNAME#"),
package = "#PKGNAME#",
src = ".",
script = modules,
meta = list(type = "module") # <------ !
)
dependencies <- append(dependencies, list(modules))
}
Specifically, the following line doesn't do what you maybe thought it does:
leprechaun/inst/template/R/assets.R
Line 66 in 345dd89
<meta name="type" content="module">
to the head, as can be seen above. This is also the documented behavior of htmltools::htmlDependency()
.
htmltools::htmlDependency()
allows the use of a named list with src
and any other valid <script> attributes
as input to the script
argument. Another useful feature is, that it allows to use
An unnamed list, containing a combination of named list with the fields mentioned previously, and strings
A simple way to fix the issue at hand would be to replace the code above with
if(!is.null(modules)){
modules <- lapply(modules, \(src) list(src = src, type = "module"))
modules <- htmlDependency(
"pitui.poc-modules",
version = utils::packageVersion("pitui.poc"),
package = "pitui.poc",
src = ".",
script = modules
)
dependencies <- append(dependencies, list(modules))
}
This will add the correct script tags to the header for the modules:
<script src="[..]/my_module.js" type="module"></script>
It should be possible to further simplify create_assets()
by processing all javascript dependencies at the same time, and simply wrapping those that are modules in lists with an additional type = "module"
element. Something along the lines of:
# in serveAssets()
#...
# JavaScript files
javascript <- list.files(
system.file(package = "#PKGNAME#"),
recursive = TRUE,
pattern = ".js$"
)
is_module <- basename(javascript) %in% modules
if (sum(is_module)) {
javascript <- lapply(seq_along(javascript), \(i) {
if(is_module[i]) list(src = javascript[i], type = "module") else javascript[i]
})
}
#...
or, using purrr:
purrr::map2(javascript, is_module, \(f, is_module) if(is_module) list(src = f, type = "module") else f )
(not tested)
We need to get rid of the build step.
It should be executed on document
with roclet or some other way.
Hi there—leprechaun is an excellent package! It’s a wonderful addition to the shiny ecosystem :)
I noticed in the leprechaun::use_config()
function, the cli output lists the following:
leprechaun::use_config()
✔ Creating inst/config.R
✔ Creating inst/config.yml
✔ Adding 'yaml' to Imports in DESCRIPTION
And it actually creates inst/config.yml
and R/config.R
├── DESCRIPTION
├── NAMESPACE
├── R/
│ ├── _disable_autoload.R
│ ├── assets.R
│ ├── config.R
│ ├── input-handlers.R
│ ├── leprechaun-utils.R
│ ├── run.R
│ ├── server.R
│ ├── ui.R
│ └── zzz.R
└── inst/
├── assets
├── config.yml
├── dev
├── img
└── run
The link to the cli function is here
I didn't see any contributing guidelines, so I didn't open a PR :)
Allow ignoring files in serveAssets
, see JohnCoene/packer#23
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.