diff --git a/CHANGELOG.md b/CHANGELOG.md
index dac32978..d94c3d51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
## Changes since last CRAN release
-* `3c5eb84c (HEAD -> master)` [_`dipterix`_]: Fixed the depth issue in electrode material shader
-* `583d267e (origin/master, origin/HEAD)` [_`dipterix`_]: Set maximum render length cut-off for electrode prototypes
+* `cb5aed88 (HEAD -> master)` [_`dipterix`_]: Avoid using pandoc to save the whole page self-contained
+* `bb7ba967 (origin/master, origin/HEAD)` [_`dipterix`_]: Fixed the depth issue in electrode material shader
+* `583d267e` [_`dipterix`_]: Set maximum render length cut-off for electrode prototypes
* `4037eddb` [_`dipterix`_]: Added model tangent (usually the direction) to electrode shader so outlines are correctly visualized
* `da148714` [_`dipterix`_]: Fixed electrode prototype rendering issue (color) on Windows
* `eda02a82` [_`dipterix`_]: Fixed the color map for discrete values
diff --git a/DESCRIPTION b/DESCRIPTION
index 8afc5360..8ca31516 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
Package: threeBrain
Type: Package
Title: Your Advanced 3D Brain Visualization
-Version: 1.1.1.9017
+Version: 1.1.1.9018
Authors@R: c(
person("Zhengjia", "Wang", email = "dipterix.wang@gmail.com", role = c("aut", "cre", "cph")),
person("John", "Magnotti", email = "John.Magnotti@Pennmedicine.upenn.edu", role = c("ctb", "res")),
diff --git a/R/threejs_brain.R b/R/threejs_brain.R
index 875fac7f..9d6005df 100644
--- a/R/threejs_brain.R
+++ b/R/threejs_brain.R
@@ -474,22 +474,73 @@ save_brain <- function(widget, path, title = '3D Viewer', as_zip = FALSE, ...){
widget$x$settings$cache_folder <- "#"
# selfcontained = FALSE to save all data information
+ temp_file <- file.path(wdir, "_tmp.html")
htmlwidgets::saveWidget(
widget,
- file = file.path(wdir, "_tmp.html"),
+ file = temp_file,
selfcontained = FALSE,
title = title,
libdir = "_lib"
)
# Use htmlwidgets to save all js and css to html
- htmlwidgets::saveWidget(
- widget,
- file = file.path(wdir, "_tmp.html"),
- selfcontained = TRUE,
- title = title,
- libdir = "lib"
- )
+ html_text <- readLines(temp_file)
+
+ # convert
+ js_lines <- which(grepl(
+ x = html_text,
+ pattern = '(src=.*js)'
+ ))
+
+ # convert link[rel=stylesheet] to
+ css_lines <- which(grepl(
+ x = html_text,
+ pattern = '(href=.*css)'
+ ))
+
+ readlines_quiet <- function(path) {
+ suppressWarnings({
+ readLines(path)
+ })
+ }
+
+ # perform self-contained conversion/replacement of JS
+ if(length(js_lines) > 0) {
+ html_text[js_lines] <- lapply(js_lines, function(js_line) {
+ js_file <- sub(x = html_text[js_line],
+ pattern = '.*src=[":\'](.*\\.js).*',
+ replacement = "\\1")
+ js_content <- paste0("",
+ collapse = "\n")
+ })
+ }
+
+
+ # perform self-contained conversion/replacement of JS
+ if(length(css_lines) > 0) {
+ html_text[css_lines] <- lapply(css_lines, function(css_line) {
+ css_file <- sub(x=html_text[css_line], pattern='.*href=[":\'](.*\\.css).*', replacement="\\1")
+ css_content <- paste0(
+ "",
+ collapse="\n"
+ )
+ })
+ }
+
+ # save self-contained html
+ write(paste0(html_text, collapse = "\n"), file = temp_file)
+
+ # htmlwidgets::saveWidget(
+ # widget,
+ # file = file.path(wdir, "_tmp.html"),
+ # selfcontained = TRUE,
+ # title = title,
+ # libdir = "lib"
+ # )
# modify the html so the data is injected as data URI
index <- file.path(wdir, "_tmp.html")