knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6, fig.height = 3.5, dev = 'png', dpi = 320
)
# Load necessary R packages
library(selr)
arrests_plot <- ggplot2::qplot(Murder, Assault, data = USArrests, main = "Arrests")
iris_plot <- ggplot2::qplot(Sepal.Length, Sepal.Width, data = iris, main = "Iris")
cars_plot <- ggplot2::qplot(mpg, wt, data = mtcars, colour = I("red"), main = "Cars")
# For this particular HTML document, import the necessary Javascript
add_javascript(in_html_doc = TRUE)
add_selector(sel_id = 'ts_1')
sel_text(sel_id = 'ts_1',
         options = c('Option_1' = "A comparison of U.S. states' murder and assault rates.",
                     'Option_2' = "Your typical iris plot.",
                     'Option_3' = "Yet another mtcars plot."))
image_paths <- c(
  'Option_1' = system.file("example-images/Arrests_Plot.png", package = 'selr'),
  'Option_2' = system.file("example-images/Iris_Plot.png", package = 'selr'),
  'Option_3' = system.file("example-images/Cars_Plot.png", package = 'selr')
)

sel_image(sel_id = 'ts_1',
          options = image_paths,
          embed = TRUE)
sel_plot(sel_id = "ts_1",
         options = list('Option_1' = arrests_plot,
                        'Option_2' = iris_plot,
                        'Option_3' = cars_plot),
         fig_output_dir = NULL,
         dev = 'png', fig.width = 6, fig.height = 3, dpi = NULL,
         embed = TRUE)


bschneidr/r_html_select documentation built on April 30, 2021, 8:53 a.m.