Closed willgearty closed 2 months ago
On a recent project, we added code that runs after shinylive::export
so we could support custom
destdir = 'site'
title_element_text <- " <title>My Project</title>"
link_element_text <- ' <link rel="shortcut icon" href="data:image/png;base64,A_PNG_FILE_BASE64_ENCODED_STRING" type="image/png">'
shinylive_file_location <- file.path(destdir, "index.html")
shinylive_html_file <- readLines(shinylive_file_location)
line_number_of_title_element <- grep("<title>", shinylive_html_file)
new_shinylive_html_file <- c(
shinylive_html_file[1:(line_number_of_title_element-1)],
title_element_text,
link_element_text,
shinylive_html_file[(line_number_of_title_element+1):(length(shinylive_html_file))]
)
writeLines(new_shinylive_html_file, shinylive_file_location)
This overwrites the index.html
file in destdir. I bet shinylive will eventually support this, and then we can abandon this extra script.
The templates themselves live in shinylive in the export_template folder, which both makes sense because it includes shinylive-specific code that might change and also limits our flexibility to change the template because both the R and Python packages rely on the template and are therefore coupled to its format.
I see a couple options here that might be worth pursuing:
The most backwards-compatible way forward would be for shinylive::export()
to gain an template_dir
argument that would be an opportunity to provide a path to a directory containing a modified export template.
Users would copy the template_dir
from the local shinylive assets (we'd provide instructions in the docs, but would rely on un-exported functions). Then, they'd modify the templates as needed.
Additionally, there is clearly a general need to be able to customize typical parts of the template, like the title
. We could also add template_params
, which would take a list of parameters to be interpolated into the template. We'd use a list instead of individual arguments -- e.g. template_params = list(title = "My Dashboard")
instead of title = "My Dashboard"
-- so that the template can evolve without requiring API changes in the shinylive packages.
If we switch to using glue for the template interpolation, this would also allow custom templates to have their own placeholder and interpolation strings.
I'm looking to have a custom index.html file for my shiny app. Nothing flashy, just a custom
<title>
and favicon location. The problem is, every time I runshinylive::export()
to update app.json, it also clobbers the index.html file. Is there a way to prevent this or to haveexport()
check my app directory for a custom index.html file and use that instead?