R/neptune_file_as_html.R

Defines functions neptune_file_as_html

Documented in neptune_file_as_html

neptune_file_as_html <-
  function(x) {
    if ("ggplot" %in% class(x)) {
      pth <- paste0(tempfile(), '.html')
      htmlwidgets::saveWidget(as_widget(ggplotly(x)),
                              selfcontained = TRUE,
                              file = pth)
      file_ <-
        reticulate::import("neptune.new.types")$File(path = pth)
      return(file_)
    }
    if ("plotly" %in% class(x)) {
      pth <- paste0(tempfile(), '.html')
      htmlwidgets::saveWidget(as_widget(x),
                              selfcontained = TRUE,
                              file = pth)
      file_ <-
        reticulate::import("neptune.new.types")$File(path = pth)
      return(file_)
    }
    reticulate::import("neptune.new.types")$File$as_html(x)
  }

Try the neptune package in your browser

Any scripts or data that you put into this service are public.

neptune documentation built on April 13, 2022, 5:14 p.m.