Experiment
library(flipbookr)
chunk_reveal_live <- function (chunk_name,
break_type = "auto",
dir = dirname(rstudioapi::getSourceEditorContext()$path),
code_file_name = paste0(dir, "/", chunk_name, ".R"),
rmd_path = paste0(dir, "/", chunk_name, "_chunk_flipbook.Rmd"),
title = stringr::str_replace_all(chunk_name, "_|\\.", " "),
subtitle = "",
author = "",
url = paste0(dir, "/",
chunk_name, "_chunk_flipbook.html"),
height = 325,
font_size = 120,
title_page = F, ...) {
save.image(paste0(dir, "/current_image.Rdata"))
flipbookr:::return_chunk_code(chunk_name = chunk_name) %>%
paste(collapse = "\n") %>%
writeLines(code_file_name)
flipbookr:::write_instant_flipbook_source(
chunk_name = chunk_name,
break_type = break_type,
code_file_name = code_file_name, rmd_path = rmd_path,
title = title, subtitle = subtitle, author = author,
font_size = font_size, title_page = title_page)
# print(rstudioapi::isAvailable())
tempdir <- tempfile()
dir.create(tempdir)
dir.create(file.path(tempdir, "libs"))
rmarkdown::render(rmd_path, quiet = F) # local copy
temphtmlFile <- file.path(tempdir, paste0(chunk_name, "_chunk_flipbook.html"))
file.copy(url, temphtmlFile, overwrite = T)
file.copy(from = file.path(dir, "libs"),
to = file.path(tempdir, "libs"),
overwrite = TRUE,
recursive = TRUE,
copy.mode = TRUE)
message("rendering...")
# make flipbook assets
try(rmarkdown::render(rmd_path, output_file = temphtmlFile, quiet = T),
silent = T) # temp copy of copy
rstudioapi::viewer(file.path(temphtmlFile), height = height)
}
if (FALSE) {
# run an application inside the IDE
rstudioapi::viewer("http://localhost:8100")
# run an application and request a height of 500 pixels
rstudioapi::viewer("http://localhost:8100", height = 500)
# use 'viewer' option if set, or `utils::browseURL()` if unset
viewer <- getOption("viewer", default = utils::browseURL)
viewer("http://localhost:8100")
# generate a temporary html file and display it
dir <- tempfile()
dir.create(dir)
htmlFile <- file.path(dir, "index.html")
# (code to write some content to the file)
rstudioapi::viewer(htmlFile)
}
library(ggplot2)
ggplot(cars) +
aes(x = speed) +
aes(y = dist) +
geom_point()