--- title: "Introduction to lcars" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Introduction to lcars} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", out.width = "100%", message = FALSE, warning = FALSE, error = FALSE ) ``` ## Making a static plot This examples adds an LCARS-style border around a static plot. Keep in mind that while the `lcars_border()` function below takes a ggplot object, the result is not a returnable ggplot object. The function uses the `grid` package underneath the hood and draws the necessary elements using viewports. ```{r ex-1} library(lcars) library(trekcolors) library(ggplot2) library(grid) library(png) logo <- rasterGrob(readPNG(system.file("stlogo-white.png", package = "lcars"))) clrs <- c("#FF3030", "#FFFF33", "#20B2AA") g <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_point() + theme_lcars_dark() + coord_cartesian(clip = "off") + annotation_custom(logo, xmin = 9.4, xmax = Inf, ymin = 3.6, ymax = Inf) + scale_color_manual(values = clrs) len_frac <- c(0.55, 0.25, 0.2, 0.4, 0.1, 0.2, 0.1, 0.1) n_seg <- c(1, 2, 0, 8) corner_colors <- c("chestnut-rose", "lilac", rep("pale-canary", 2)) side_colors <- list("pale-canary", c("anakiwa", "lilac"), NA, c("#000000", rep("anakiwa", 2), rep("orange-peel", 5))) side_labels <- list( "R 47.0.2", c("47", "B4"), NA, c("LCARS", "47174-A", "...", "O'Brien", "Lefler", "La Forge", "Barclay", "Argyle")) lcars_border(g, corners = 1:3, length_frac = len_frac, side_n_segments = n_seg, corner_color = corner_colors, side_color = side_colors, side_label = side_labels, label_size = 0.7) text(2.8, 0.1, "Iris dataset (classic Terran flora sample)", col = lcars_colors("anakiwa"), font = 2, cex = 0.7) text(7.55, 0.1, "LCARS BETA R Interface v0.0.1", col = lcars_colors("pale-canary"), font = 2, cex = 0.7) ``` As you can see, a decent plot is still going to take some customization with additional commands in order to give it the level of polish it deserves. But this is just the appetizer; next is the Shiny version. ## LCARS in Shiny In the `lcars` package, functions whose names are lowercase and contain underscores deal with general R use. Functions whose names use camel case are related to Shiny. First, use `lcarsPage()` to set up the Shiny UI. This is a wrapper around Shiny's `bootstrapPage()`. It loads the required CSS and other assets. There are several functions you can explore. There are a handful of simple wrappers around various Shiny inputs that give them an LCARS aesthetic, but not many currently and they will continue to be improved upon in subsequent package versions. The primary function of interest is `lcarsBox()`. This is the container that captures the LCARS style. Additional functions worth focusing on include `lcarsHeader()` for breaking up sections of the UI; also `lcarsButton()` and `lcarsToggle()`, which in conjunction with `buttonColumn()` produce column inputs that fit well into the sidebars of an `lcarsBox()`. Here is a simple example. ```{r ex1, eval=FALSE} if (interactive()) { ui <- lcarsPage( lcarsBox( fluidRow( column(3, h4("Main panel area"), HTML("
Some paragraph text and a link with LCARS styling.
Use lcarsPage
to apply the LCARS theme and lcarsBox
to draw a characteristic box for framing content.
Many of the lcarsBox
properties are configurable.
See lcars::lcarsApp(\"box\")
for a demo