if (FALSE) { # rlang::is_interactive()
myWidgetVersion <- "1.2.3"
myWidgetDependency <- function() {
list(
bs_dependency_defer(myWidgetCss),
htmlDependency(
name = "mywidget-js",
version = myWidgetVersion,
src = system.file(package = "mypackage", "js"),
script = "mywidget.js"
)
)
}
myWidgetCSS <- function(theme) {
if (!is_bs_theme(theme)) {
return(
htmlDependency(
name = "mywidget-css",
version = myWidgetVersion,
src = system.file(package = "mypackage", "css"),
stylesheet = "mywidget.css"
)
)
}
# Compile mywidget.scss using the variables and defaults from the theme
# object.
sass_input <- sass::sass_file(system.file(package = "mypackage", "scss/mywidget.scss"))
bs_dependency(
input = sass_input,
theme = theme,
name = "mywidget",
version = myWidgetVersion,
cache_key_extra = utils::packageVersion("mypackage")
)
}
# Note that myWidgetDependency is not defined inside of myWidget. This is so
# that, if `myWidget()` is called multiple times, Shiny can tell that the
# function objects are identical and deduplicate them.
myWidget <- function(id) {
div(
id = id,
span("myWidget"),
myWidgetDependency()
)
}
}
Run the code above in your browser using DataLab