Skip to content

Commit

Permalink
WIP plotly example
Browse files Browse the repository at this point in the history
  • Loading branch information
jrosell committed Aug 6, 2024
1 parent 9b17d84 commit d2d3653
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 207 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(amb_button)
export(amb_card)
export(amb_htmlwidget)
export(amb_input_text)
export(ambhtmx)
export(button)
Expand Down
4 changes: 4 additions & 0 deletions R/components-amb.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ amb_button <- \(..., class = "rounded-1", type = "button") {
...
)
}




39 changes: 39 additions & 0 deletions R/components-htmlwidgets.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' @keywords components
#' @rdname components
#' @param widget htmlwidget to convert as a shiny.tag
#' @param ... attributes to add to the container
#' @param width to customeize the width of the container
#' @param height to customeize the width of the container
#' @export
amb_htmlwidget <- \(widget, ..., width = "100%", height = "400px") {
temp_widget_file <- NULL
widget_chr <- withr::with_tempfile("temp_widget_file", fileext = ".html", {
htmlwidgets::saveWidget(widget, temp_widget_file, selfcontained = TRUE)
lines_read <- readLines(temp_widget_file)
full_html <- paste0(lines_read, "\n", collapse = "")
full_html |>
stringr::str_replace_all("<!DOCTYPE html>", "") |>
stringr::str_replace_all('<meta charset="utf-8" />', "") |>
stringr::str_replace_all("<title>.*</title>", "") |>
stringr::str_replace_all("<html.*>", "") |>
stringr::str_replace_all("</html>", "") |>
stringr::str_replace_all("<head>", "") |>
stringr::str_replace_all("</head>", "") |>
stringr::str_replace_all("<body.*>", "") |>
stringr::str_replace_all("</body>", "")
})
widget_html <- htmltools::HTML(widget_chr)
widget_tags <- htmltools::tags$div(widget_html, width = width, height = height, ...)
widget_tags
}

# #'@noRd
# amb_htmlwidget_data <- \(widget, ..., width = "100%", height = "400px") {
# widget_chr <- withr::with_tempfile("temp_widget_file", fileext = ".html", {
# htmlwidgets::saveWidget(widget, temp_widget_file, selfcontained = TRUE)
# readLines(temp_widget_file) |>
# paste0("\n", collapse = "")
# })
# start_pattern <- '<script type="application/json" data-for="'
# stringr::str_extract(widget_chr, glue::glue('{start_pattern}.*</script>'))
# }
6 changes: 2 additions & 4 deletions R/dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ rebuild_docs_and_check <- function() {
# spain_ccaas <- readr::read_rds("inst/extdata/spain_ccaas.rds")
# spain_provinces <- readr::read_rds("inst/extdata/spain_provinces.rds")
# usethis::use_data(spain_ccaas, spain_provinces, overwrite = TRUE)
usethis::use_namespace()
devtools::document()
usethis::use_namespace()
devtools::check(document = TRUE)
pkgdown::build_site(preview = FALSE)
utils::browseURL(here::here("docs", "index.html"), browser = "firefox")
devtools::check()
devtools::load_all()
# usethis::use_version(which = "dev", push = FALSE)
}
4 changes: 4 additions & 0 deletions R/rendering.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
render_page <- \(main = NULL, page_title = NULL, head_tags = NULL) {
penv <- rlang::env_parent()
genv <- rlang::global_env()
if (is_debug_enabled()) cat(glue::glue("render_page {page_title}\n\n"))
if (is.null(page_title)){
page_title <- penv[["page_title"]]
}
if (is_debug_enabled()) cat(glue::glue("render_page penv {page_title}\n\n"))
if (is.null(page_title)){
page_title <- genv[["page_title"]]
}
if (is_debug_enabled()) cat(glue::glue("render_page genv {page_title}\n\n"))
if (is.null(page_title)){
page_title <- "ambhtmx"
}
if (is_debug_enabled()) cat(glue::glue("render_page default {page_title}\n\n"))
if (is.null(main)){
main <- penv[["main"]]
}
Expand Down
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pandoc: 3.1.12.3
pkgdown: 2.1.0
pkgdown_sha: ~
articles: {}
last_built: 2024-08-05T22:15Z
last_built: 2024-08-06T13:30Z
urls:
reference: https://jrosell.github.io/ambhtmx/reference
article: https://jrosell.github.io/ambhtmx/articles
8 changes: 8 additions & 0 deletions docs/reference/amb_htmlwidget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<meta http-equiv="refresh" content="0;URL=https://jrosell.github.io/ambhtmx/reference/components.html" />
<meta name="robots" content="noindex">
<link rel="canonical" href="https://jrosell.github.io/ambhtmx/reference/components.html">
</head>
</html>

20 changes: 17 additions & 3 deletions docs/reference/components.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

Loading

0 comments on commit d2d3653

Please sign in to comment.