Materialise Framework

Setup environment

library(dplyr)
library(htmltools)
library(econR)
.GlobalEnv$web <- econR::Web()
web$foldername="docs2" # output folder name
web$html_filename <- "index.html"

Body elements

Widgets

library(plotly)
plt_widget <- subplot(
  plot_ly(mpg, x = ~cty, y = ~hwy, name = "default"),
  plot_ly(mpg, x = ~cty, y = ~hwy) %>% 
    add_markers(alpha = 0.2, name = "alpha")
)
el_widget <- tags$div(class="container",
             tags$div(class="row",
                      tags$div(class="col s12",
                               plt_widget)
                      ))

main

main <- tags$main(
      tags$h5(class="center-align",
      "Materialise with Plotly")
    )

Body tag list

bodyTagList <- {
  htmltools::tagList(
    main,
    el_widget
  )
}

HTML Structure

html_placeholder <- tags$html(
  tags$head(
    do.call(htmltools::tagList, headTags),
    tags$meta(
      name="viewport",
      content="width=device-width, initial-scale=1.0"
    )
  ),
  tags$body(
    bodyTagList #do.call(htmltools::tagList, bodyTags)
  )
)

Dependencies

Head Tags

headTags <- {
  htmltools::tagList(
    htmltools::tags$link(
      href="https://fonts.googleapis.com/icon?family=Material+Icons",
      rel="stylesheet"
    )
  )
}

Define dependency

myDependency <- htmltools::htmlDependency(
  name="myown",
  version="1.0",
  src=c(filepath=web$cssJsPath),
  stylesheet = "css/mystyle.css",
  script = "js/mydesign.js",
  head = '<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+Sans+TC">
'
)
local_jquery <- 
  htmltools::htmlDependency(
    name="jquery",
    version="3.5.1",
    src=c(href = "lib/jquery-3.5.1"),
    # to use the same library here must use href, not filepath; otherwise, the current jquery system will be removed.
    script = c("jquery.min.js")
  )

Attach dependency

html_complete <- 
  htmltools::tagList(
    html_placeholder,
    web$htmlDependencies$materialise(),
    local_jquery, 
    myDependency
  )

Save

htmltools::save_html(
  html_complete, 
  file = web$output_filepath(),
  libdir="lib"
)

Browse

web$browse()


tpemartin/rmd2drake documentation built on Nov. 2, 2022, 10:14 a.m.