### build_aes examples Source: https://dreamrs.github.io/esquisse/reference/build_aes.html Examples demonstrating basic usage, explicit geom, handling count data, and integration with ggplot2. The output of each call is shown as comments. ```r # Classic build_aes(iris, x = "Sepal.Width") #> Aesthetic mapping: #> * `x` -> `Sepal.Width` build_aes(iris, x = "Sepal.Width", y = "Sepal.Width") #> Aesthetic mapping: #> * `x` -> `Sepal.Width` #> * `y` -> `Sepal.Width` # Explicit geom : no change build_aes(iris, x = "Species", geom = "bar") #> Aesthetic mapping: #> * `x` -> `Species` # Little trick if data is count data df <- data.frame( LET = c("A", "B"), VAL = c(4, 7) ) build_aes(df, x = "LET", y = "VAL", geom = "bar") #> Aesthetic mapping: #> * `x` -> `LET` #> * `y` -> `VAL` # e.g. : library(ggplot2) ggplot(df) + build_aes(df, x = "LET", y = "VAL", geom = "bar") + geom_bar(stat = "summary", fun = "mean") ``` -------------------------------- ### Launch esquisse with esquisser() Source: https://dreamrs.github.io/esquisse/reference/esquisse.html Starts the esquisse Shiny gadget. The example is wrapped in if (FALSE) and # \dontrun{} to prevent execution during package checks. Use esquisser(mtcars) to launch with the mtcars dataset pre-loaded. ```R if (FALSE) { # \dontrun{ esquisser() # launch esquisse with specific data: esquisser(mtcars) } # } ``` -------------------------------- ### Install development version from GitHub Source: https://dreamrs.github.io/esquisse/ Installs the development version of esquisse from GitHub using remotes::install_github(). ```r remotes::install_github("dreamRs/esquisse") ``` -------------------------------- ### ggcall() with coordinates Source: https://dreamrs.github.io/esquisse/reference/ggcall.html Shows two examples of using the coord parameter, one without arguments and one with coord_args. ```R # Coordinates ggcall( data = "mtcars", mapping = list(x = "mpg", y = "wt"), geom = "point", coord = "fixed" ) #> ggplot(mtcars) + aes(x = mpg, y = wt) + geom_point() + coord_fixed() ggcall( data = "mtcars", mapping = list(x = "mpg", y = "wt"), geom = "point", coord = "fixed", coord_args = list(ratio = 5) ) #> ggplot(mtcars) + aes(x = mpg, y = wt) + geom_point() + coord_fixed(ratio = 5) ``` -------------------------------- ### Install esquisse from CRAN Source: https://dreamrs.github.io/esquisse/ Installs the stable version of esquisse from CRAN using install.packages(). ```r install.packages("esquisse") ``` -------------------------------- ### Interactive Shiny example using dropInput Source: https://dreamrs.github.io/esquisse/reference/dropInput.html An interactive Shiny app that creates a dropdown input with icon choices and displays the selected value. The example is wrapped in an if (interactive()) block and requires the shiny and esquisse packages. ```r if (interactive()) { library(shiny) library(esquisse) ui <- fluidPage( tags$h2("Drop Input"), dropInput( inputId = "mydrop", choicesNames = tagList( list(icon("home"), style = "width: 100px;"), list(icon("flash"), style = "width: 100px;"), list(icon("cogs"), style = "width: 100px;"), list(icon("fire"), style = "width: 100px;"), list(icon("users"), style = "width: 100px;"), list(icon("info"), style = "width: 100px;") ), choicesValues = c("home", "flash", "cogs", "fire", "users", "info"), dropWidth = "220px" ), verbatimTextOutput(outputId = "res") ) server <- function(input, output, session) { output$res <- renderPrint({ input$mydrop }) } shinyApp(ui, server) } ``` -------------------------------- ### ggplot_to_ppt example with Shiny gadget and object name Source: https://dreamrs.github.io/esquisse/reference/ggplot_to_ppt.html Example usage: launches the Shiny gadget interactively, or passes the name of a ggplot object. The function returns the path to a temporary PowerPoint file. ```r # Shiny gadget if (interactive()) { ggplot_to_ppt() # Or with an object's name library(ggplot2) p <- ggplot(iris) + geom_point(aes(Sepal.Length, Sepal.Width)) ggplot_to_ppt("p") } ``` -------------------------------- ### esquisser interactive usage examples Source: https://dreamrs.github.io/esquisse/reference/esquisser.html Example block showing how to launch esquisse interactively. It demonstrates launching with iris data, specifying the viewer as 'browser', setting options in .Rprofile, and using a custom port via shiny.port. ```r if (interactive()) { # Launch with : esquisser(iris) # If in RStudio it will be launched by default in dialog window # If not, it will be launched in browser # Launch esquisse in browser : esquisser(iris, viewer = "browser") # You can set this option in .Rprofile : options("esquisser.viewer" = "viewer") # or options("esquisser.viewer" = "browser") # esquisse use shiny::runApp # see ?shiny::runApp to see options # available, example to use custom port: options("shiny.port" = 8080) esquisser(iris, viewer = "browser") } ``` -------------------------------- ### Example: Matching parameters for different geometries Source: https://dreamrs.github.io/esquisse/reference/match_geom_args.html Defines a list of parameters and then calls match_geom_args for histogram, violin, bar, and point geometries, showing the filtered output for each. ```r # List of parameters params <- list( bins = 30, scale = "width", adjust = 2, position = "stack", size = 1.6, fill = "#112246" ) # Search arguments according to geom match_geom_args(geom = "histogram", args = params) #> $bins #> [1] 30 #> #> $position #> [1] "stack" #> #> $fill #> [1] "#112246" #> match_geom_args(geom = "violin", args = params) #> $scale #> [1] "width" #> #> $adjust #> [1] 2 #> #> $position #> [1] "stack" #> #> $fill #> [1] "#112246" #> match_geom_args(geom = "bar", args = params, add_aes = FALSE) #> $position #> [1] "stack" #> match_geom_args(geom = "point", args = params) #> $position #> [1] "stack" #> #> $size #> [1] 1.6 #> #> $fill #> [1] "#112246" #> match_geom_args(geom = "point", args = params, add_aes = FALSE) #> $position #> [1] "stack" #> ``` -------------------------------- ### Interactive example for updateDragulaInput Source: https://dreamrs.github.io/esquisse/reference/updateDragulaInput.html This example shows a complete Shiny app that updates a dragulaInput widget's choices based on a radio button selection. It requires the shiny and esquisse packages and is wrapped in an interactive() check. ```r if (interactive()) { library("shiny") library("esquisse") ui <- fluidPage( tags$h2("Update dragulaInput"), radioButtons( inputId = "update", label = "Dataset", choices = c("iris", "mtcars") ), tags$br(), dragulaInput( inputId = "myDad", sourceLabel = "Variables", targetsLabels = c("X", "Y", "fill", "color", "size"), choices = names(iris), replace = TRUE, width = "400px", status = "success" ), verbatimTextOutput(outputId = "result") ) server <- function(input, output, session) { output$result <- renderPrint(str(input$myDad)) observeEvent(input$update, { if (input$update == "iris") { updateDragulaInput( session = session, inputId = "myDad", choices = names(iris), status = "success" ) } else { updateDragulaInput( session = session, inputId = "myDad", choices = names(mtcars) ) } }, ignoreInit = TRUE) } shinyApp(ui, server) } ``` -------------------------------- ### palettePicker section header Source: https://dreamrs.github.io/esquisse/reference/input-colors.html The palettePicker section is introduced but the code block is incomplete; only the comment and library calls are shown. The full example is not displayed on this page. ```R # palettePicker ----------------------------------------------------------- library(shiny) library(esquisse) library(scales) ``` -------------------------------- ### Shiny app example using save_multi_ggplot module Source: https://dreamrs.github.io/esquisse/reference/save-ggplot-multi-module.html Complete Shiny application demonstrating how to use save_multi_ggplot_ui and save_multi_ggplot_server. It creates five ggplot objects and passes them as a reactive list with code and labels. The app is launched with shinyApp when interactive. ```R library(shiny) library(ggplot2) library(esquisse) library(bslib) #> #> Attaching package: ‘bslib’ #> The following object is masked from ‘package:utils’: #> #> page ui <- page_fluid( theme = bs_theme_esquisse(), save_multi_ggplot_ui("mod") ) server <- function(...) { p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p3 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec)) p4 <- ggplot(mtcars) + geom_bar(aes(carb)) p5 <- ggplot(presidential) + geom_segment(aes(y = name, x = start, xend = end)) + geom_point(aes(y = name, x = start)) + geom_point(aes(y = name, x = end)) save_multi_ggplot_server( id = "mod", plot_list_r = reactive(list( list( ggobj = p1, code = "ggplot(mtcars) + geom_point(aes(mpg, disp))", label = "Plot 1" ), list( ggobj = p2, code = "ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))", label = "Plot 2" ), list( ggobj = p3, code = "ggplot(mtcars) + geom_smooth(aes(disp, qsec))", label = "Plot 3" ), list( ggobj = p4, code = "ggplot(mtcars) + geom_bar(aes(carb))", label = "Plot 4" ), list( ggobj = p5, code = "ggplot(presidential) + geom_segment(aes(y = name, x = start, xend = end)) + geom_point(aes(y = name, x = start)) + geom_point(aes(y = name, x = end))", label = "Plot 5" ) )) ) } if (interactive()) shinyApp(ui, server) ``` -------------------------------- ### Interactive Shiny example using safe_ggplot Source: https://dreamrs.github.io/esquisse/reference/safe_ggplot.html An interactive example that runs only in an interactive R session. It creates a Shiny app with a select input for choosing a variable (including a non-existent option) and a plot output. The server uses safe_ggplot to render the plot, handling potential errors gracefully. ```r if (interactive()) { library(shiny) library(ggplot2) ui <- fluidPage( fluidRow( column( width = 3, selectInput( inputId = "var", label = "Var:", choices = c("Sepal.Width", "Do.Not.Exist") ) ), column( width = 9, plotOutput(outputId = "plot") ) ) ) server <- function(input, output, session) { output$plot <- renderPlot({ p <- ggplot(iris) + geom_point(aes_string("Sepal.Length", input$var)) safe_ggplot(p) }) } shinyApp(ui, server) } ``` -------------------------------- ### Shiny app using save_ggplot module Source: https://dreamrs.github.io/esquisse/reference/save-ggplot-module.html Complete Shiny application example from the documentation. It creates a plot of the economics dataset, opens a save modal on button click, and initializes the save_ggplot server. Requires shiny, ggplot2, and esquisse packages. ```r library(shiny) library(ggplot2) library(esquisse) ui <- fluidPage( tags$h2("Save a ggplot"), selectInput("var", "Variable:", names(economics)[-1]), plotOutput("plot", width = "600px"), actionButton("save", "Save this plot") ) server <- function(input, output, session) { rv <- reactiveValues(plot = NULL) output$plot <- renderPlot({ rv$plot <- ggplot(economics) + geom_line(aes(date, !!sym(input$var))) + theme_minimal() rv$plot }) observeEvent(input$save, { save_ggplot_modal("ID", "Save plot") }) save_ggplot_server("ID", rv) } if (interactive()) shinyApp(ui, server) ``` -------------------------------- ### Example: Both scales with which_pal_scale Source: https://dreamrs.github.io/esquisse/reference/which_pal_scale.html Demonstrates specifying both color and fill aesthetics with different types: color_type 'discrete' and fill_type 'continuous'. Returns scale_fill_distiller and scale_color_brewer, both with palette 'Blues' and direction 1. ```r # Both scales which_pal_scale( mapping = aes(color = var1, fill = var2), palette = "Blues", color_type = "discrete", fill_type = "continuous" ) #> $scales #> [1] "scale_fill_distiller" "scale_color_brewer" #> #> $args #> $args$scale_fill_distiller #> $args$scale_fill_distiller$palette #> [1] "Blues" #> #> $args$scale_fill_distiller$direction #> [1] 1 #> #> #> $args$scale_color_brewer #> $args$scale_color_brewer$palette #> [1] "Blues" #> #> $args$scale_color_brewer$direction #> [1] 1 #> #> #> ``` -------------------------------- ### Shiny app with colorPicker examples Source: https://dreamrs.github.io/esquisse/reference/input-colors.html Complete Shiny app demonstrating multiple colorPicker widgets: vector choices, list of vectors, custom textColor, plainColor with multiple selection, and dynamic update via updateColorPicker. Requires library(shiny), library(esquisse), and library(scales). The app runs only if interactive(). ```R # colorPicker ------------------------------------------------------------- library(shiny) library(esquisse) library(scales) ui <- fluidPage( tags$h2("colorPicker examples"), fluidRow( column( width = 3, colorPicker( inputId = "col1", label = "With a vector of colors:", choices = brewer_pal(palette = "Dark2")(8) ), verbatimTextOutput("res1"), colorPicker( inputId = "col5", label = "Update colors:", choices = brewer_pal(palette = "Blues", direction = -1)(8), textColor = "#FFF" ), verbatimTextOutput("res5"), radioButtons( "update", "Colors", c("Blues", "Greens", "Reds"), inline = TRUE ) ), column( width = 3, colorPicker( inputId = "col2", label = "Change text color:", choices = brewer_pal(palette = "Blues")(8), textColor = c("black", "black", "black", "white", "white", "white", "white", "white") ), verbatimTextOutput("res2") ), column( width = 3, colorPicker( inputId = "col3", label = "With a list of vector of colors:", choices = list( "Blues" = brewer_pal(palette = "Blues")(8), "Reds" = brewer_pal(palette = "Reds")(8), "Greens" = brewer_pal(palette = "Greens")(8) ) ), verbatimTextOutput("res3") ), column( width = 3, colorPicker( inputId = "col4", label = "Plain color & multiple choices:", choices = brewer_pal(palette = "Paired")(8), plainColor = TRUE, multiple = TRUE, pickerOpts = list(`selected-text-format`= "count > 3") ), verbatimTextOutput("res4") ) ) ) server <- function(input, output, session) { output$res1 <- renderPrint(input$col1) output$res2 <- renderPrint(input$col2) output$res3 <- renderPrint(input$col3) output$res4 <- renderPrint(input$col4) output$res5 <- renderPrint(input$col5) observeEvent(input$update, { updateColorPicker( inputId = "col5", choices = brewer_pal(palette = input$update, direction = -1)(8), textColor = "#FFF" ) }) } if (interactive()) { shinyApp(ui, server) } ``` -------------------------------- ### Shiny app with dragulaInput examples Source: https://dreamrs.github.io/esquisse/reference/dragulaInput.html Complete Shiny application showing four dragulaInput widgets with different layouts (default, same row, two rows, two rows not filled) and server-side output using renderPrint and str. The output is a list with source and targets slots. ```R library(shiny) library(esquisse) ui <- fluidPage( tags$h2("Demo dragulaInput"), tags$br(), fluidRow( column( width = 6, dragulaInput( inputId = "dad1", label = "Default:", sourceLabel = "Source", targetsLabels = c("Target 1", "Target 2"), choices = month.abb, width = "100%" ), verbatimTextOutput(outputId = "result1"), tags$br(), dragulaInput( inputId = "dad3", label = "On same row:", sourceLabel = "Source", targetsLabels = c("Target 1", "Target 2"), choices = month.abb, width = "100%", ncolSource = 1, ncolGrid = 3 ), verbatimTextOutput(outputId = "result3") ), column( width = 6, dragulaInput( inputId = "dad2", label = "Two rows:", sourceLabel = "Source", targetsLabels = c("x", "y", "color", "fill", "size", "facet"), choices = names(mtcars), width = "100%", ncolGrid = 3 ), verbatimTextOutput(outputId = "result2"), tags$br(), dragulaInput( inputId = "dad4", label = "Two rows not filled:", sourceLabel = "Source", targetsLabels = c("x", "y", "color", "fill", "size"), choices = names(mtcars), width = "100%", ncolGrid = 3 ), verbatimTextOutput(outputId = "result4") ) ) ) server <- function(input, output, session) { output$result1 <- renderPrint(str(input$dad1)) output$result2 <- renderPrint(str(input$dad2)) output$result3 <- renderPrint(str(input$dad3)) output$result4 <- renderPrint(str(input$dad4)) } if (interactive()) shinyApp(ui = ui, server = server) ``` -------------------------------- ### Examples of potential_geoms with various mappings Source: https://dreamrs.github.io/esquisse/reference/geoms.html Demonstrates potential_geoms with different aesthetic mappings: one continuous variable, automatic selection, one discrete variable, two continuous variables, and the reference output. The output shows the available geometries and which one is selected by default (auto = 1). ```R library(ggplot2) # One continuous variable potential_geoms( data = iris, mapping = aes(x = Sepal.Length) ) #> [1] "histogram" "boxplot" "violin" "density" # Automatic pick a geom potential_geoms( data = iris, mapping = aes(x = Sepal.Length), auto = TRUE ) #> [1] "histogram" # One discrete variable potential_geoms( data = iris, mapping = aes(x = Species) ) #> [1] "bar" # Two continuous variables potential_geoms( data = iris, mapping = aes(x = Sepal.Length, y = Sepal.Width) ) #> [1] "point" "jitter" "line" "step" "path" "area" "smooth" "text" #> [9] "label" "tile" # Reference used by esquisse to select available geoms # and decide which one to use by default potential_geoms_ref() #> x y geom auto #> 1 continuous empty histogram 1 #> 2 continuous empty boxplot 0 #> 3 continuous empty violin 0 #> 4 continuous empty density 0 #> 5 discrete empty bar 1 #> 6 time empty histogram 1 #> 7 time empty bar 0 #> 8 continuous discrete boxplot 0 #> 9 continuous discrete point 0 #> 10 continuous discrete jitter 0 #> 11 continuous discrete violin 0 #> 12 continuous discrete bar 1 #> 13 discrete continuous col 1 #> 14 discrete continuous bar 0 #> 15 discrete continuous boxplot 0 #> 16 discrete continuous point 0 #> 17 discrete continuous jitter 0 #> 18 discrete continuous violin 0 #> 19 discrete continuous text 0 #> 20 discrete continuous label 0 #> 21 continuous continuous point 1 #> 22 continuous continuous jitter 0 #> 23 continuous continuous line 0 #> 24 continuous continuous step 0 #> 25 continuous continuous path 0 #> 26 continuous continuous area 0 #> 27 continuous continuous smooth 0 #> 28 continuous continuous text 0 #> 29 continuous continuous label 0 #> 30 discrete discrete tile 1 #> 31 time continuous line 1 #> 32 time continuous point 0 #> 33 time continuous step 0 #> 34 time continuous area 0 #> 35 time continuous bar 0 #> 36 time continuous smooth 0 #> 37 empty continuous line 1 #> 38 empty continuous step 0 #> 39 empty continuous path 0 #> 40 empty continuous area 0 #> 41 continuous continuous tile 0 #> 42 discrete time tile 0 #> 43 time discrete tile 0 ``` -------------------------------- ### dropInput Shiny app example Source: https://dreamrs.github.io/esquisse/articles/shiny-usage.html Complete Shiny app demonstrating the dropInput widget, used to select a geom in the esquisser addin. The choices are defined with icons (home, flash, cogs, fire, users, info) and the server renders the selected value. ```R ui <- fluidPage( tags$h2("Drop Input"), dropInput( inputId = "mydrop", choicesNames = tagList( list(icon("home"), style = "width: 100px;"), list(icon("flash"), style = "width: 100px;"), list(icon("cogs"), style = "width: 100px;"), list(icon("fire"), style = "width: 100px;"), list(icon("users"), style = "width: 100px;"), list(icon("info"), style = "width: 100px;") ), choicesValues = c("home", "flash", "cogs", "fire", "users", "info"), dropWidth = "220px" ), verbatimTextOutput(outputId = "res") ) server <- function(input, output, session) { output$res <- renderPrint({ input$mydrop }) } shinyApp(ui, server) ``` -------------------------------- ### palettePicker Shiny app example Source: https://dreamrs.github.io/esquisse/articles/shiny-usage.html Complete Shiny app demonstrating the palettePicker widget, a select menu to choose a color palette. The choices include Viridis and Brewer palettes, with textColor set to white for the first five and black for the last four. The server renders the selected palette value. ```R library(scales) ui <- fluidPage( tags$h2("Palette Picker"), palettePicker( inputId = "pal", label = "Choose a palette", choices = list( "Viridis" = list( "viridis" = viridis_pal(option = "viridis")(10), "magma" = viridis_pal(option = "magma")(10), "inferno" = viridis_pal(option = "inferno")(10), "plasma" = viridis_pal(option = "plasma")(10), "cividis" = viridis_pal(option = "cividis")(10) ), "Brewer" = list( "Blues" = brewer_pal(palette = "Blues")(8), "Reds" = brewer_pal(palette = "Reds")(8), "Paired" = brewer_pal(palette = "Paired")(8), "Set1" = brewer_pal(palette = "Set1")(8) ) ), textColor = c( rep("white", 5), rep("black", 4) ) ), verbatimTextOutput(outputId = "res") ) server <- function(input, output, session) { output$res <- renderPrint({ input$pal }) } shinyApp(ui, server) ``` -------------------------------- ### Interactive Shiny example using updateDropInput Source: https://dreamrs.github.io/esquisse/reference/updateDropInput.html A complete Shiny app demonstrating how to update a dropInput's selected value and disable choices using updateDropInput. The app includes buttons to select each choice and a checkbox group to disable choices. ```r if (interactive()) { library(shiny) library(esquisse) myChoices <- tagList( list(icon("home"), style = "width: 100px;"), list(icon("flash"), style = "width: 100px;"), list(icon("cogs"), style = "width: 100px;"), list(icon("fire"), style = "width: 100px;"), list(icon("users"), style = "width: 100px;"), list(icon("info"), style = "width: 100px;") ) ui <- fluidPage( tags$h2("Update Drop Input"), fluidRow( column( width = 6, dropInput( inputId = "mydrop", choicesNames = myChoices, choicesValues = c("home", "flash", "cogs", "fire", "users", "info"), dropWidth = "220px" ), verbatimTextOutput(outputId = "res") ), column( width = 6, actionButton("home", "Select home"), actionButton("flash", "Select flash"), actionButton("cogs", "Select cogs"), actionButton("fire", "Select fire"), actionButton("users", "Select users"), actionButton("info", "Select info"), checkboxGroupInput( inputId = "disabled", label = "Choices to disable", choices = c("home", "flash", "cogs", "fire", "users", "info") ), actionButton("disable", "Disable") ) ) ) server <- function(input, output, session) { output$res <- renderPrint({ input$mydrop }) observeEvent(input$home, { updateDropInput(session, "mydrop", "home") }) observeEvent(input$flash, { updateDropInput(session, "mydrop", "flash") }) observeEvent(input$cogs, { updateDropInput(session, "mydrop", "cogs") }) observeEvent(input$fire, { updateDropInput(session, "mydrop", "fire") }) observeEvent(input$users, { updateDropInput(session, "mydrop", "users") }) observeEvent(input$info, { updateDropInput(session, "mydrop", "info") }) observeEvent(input$disable, { if (!is.null(input$disabled)) { updateDropInput(session, "mydrop", disabled = input$disabled) } else { updateDropInput(session, "mydrop", disabled = character(0)) } }) } shinyApp(ui, server) } ``` -------------------------------- ### Example: Explicitly specify type with which_pal_scale Source: https://dreamrs.github.io/esquisse/reference/which_pal_scale.html Shows how to explicitly set color_type to 'discrete' for a color aesthetic, using the 'Blues' palette. Returns scale_color_brewer with palette 'Blues' and direction 1. ```r # Explicitly specify type which_pal_scale( mapping = aes(color = variable), palette = "Blues", color_type = "discrete" ) #> $scales #> [1] "scale_color_brewer" #> #> $args #> $args$scale_color_brewer #> $args$scale_color_brewer$palette #> [1] "Blues" #> #> $args$scale_color_brewer$direction #> [1] 1 #> #> #> ``` -------------------------------- ### colorPicker Shiny app example Source: https://dreamrs.github.io/esquisse/articles/shiny-usage.html Complete Shiny app demonstrating the colorPicker widget, a select menu to choose one or several colors. The choices are generated using the Dark2 palette from scales, with white text color. The server renders the selected color value. ```R ui <- fluidPage( tags$h2("Color Picker"), colorPicker( inputId = "col", label = "Choose a color:", choices = scales::brewer_pal(palette = "Dark2")(8), textColor = "white" ), verbatimTextOutput(outputId = "res") ) server <- function(input, output, session) { output$res <- renderPrint({ input$col }) } shinyApp(ui, server) ``` -------------------------------- ### Render ggplot with export options: full Shiny app Source: https://dreamrs.github.io/esquisse/articles/shiny-usage.html Complete Shiny app using the ggplot_output UI and render_ggplot server functions to display a plot with an export menu. The example includes a selectInput for choosing a variable from the economics dataset. ```R library(shiny) library(ggplot2) library(esquisse) ui <- fluidPage( tags$h2("ggplot output"), selectInput("var", "Variable:", names(economics)[-1]), ggplot_output("MYID", width = "600px") ) server <- function(input, output, session) { render_ggplot("MYID", { ggplot(economics) + geom_line(aes(date, !!sym(input$var))) + theme_minimal() + labs( title = "A cool chart made with ggplot2", subtitle = "that you can export in various format" ) }) } if (interactive()) shinyApp(ui, server) ``` -------------------------------- ### dragulaInput Shiny app example Source: https://dreamrs.github.io/esquisse/articles/shiny-usage.html Complete Shiny app demonstrating the dragulaInput widget. The UI creates a drag-and-drop input with source label 'Source' and two targets, using iris column names as choices. The server renders the input value as a string. ```R ui <- fluidPage( tags$h2("Demo dragulaInput"), tags$br(), dragulaInput( inputId = "dad", sourceLabel = "Source", targetsLabels = c("Target 1", "Target 2"), choices = names(iris), width = "400px" ), verbatimTextOutput(outputId = "result") ) server <- function(input, output, session) { output$result <- renderPrint(str(input$dad)) } shinyApp(ui = ui, server = server) ``` -------------------------------- ### Example: Automatic guess according to data with which_pal_scale Source: https://dreamrs.github.io/esquisse/reference/which_pal_scale.html Demonstrates calling which_pal_scale with a data frame (iris) to automatically guess the scale type. For a continuous variable (Sepal.Length) it returns scale_fill_gradient, and for a discrete variable (Species) it returns scale_fill_hue with direction 1. ```r library(ggplot2) # Automatic guess according to data which_pal_scale( mapping = aes(fill = Sepal.Length), palette = "ggplot2", data = iris ) #> $scales #> [1] "scale_fill_gradient" #> #> $args #> list() #> which_pal_scale( mapping = aes(fill = Species), palette = "ggplot2", data = iris ) #> $scales #> [1] "scale_fill_hue" #> #> $args #> $args$scale_fill_hue #> $args$scale_fill_hue$direction #> [1] 1 #> #> #> ``` -------------------------------- ### ggcall() with theme and theme_args Source: https://dreamrs.github.io/esquisse/reference/ggcall.html Shows how to specify a theme and pass arguments to it, including using rlang::expr for element_text. ```R # Theme ggcall( "mtcars", list(x = "mpg", y = "wt"), theme = "theme_minimal", theme_args = list( panel.ontop = TRUE, legend.title = rlang::expr(element_text(face = "bold")) ) ) #> ggplot(mtcars) + aes(x = mpg, y = wt) + theme_minimal() + theme(panel.ontop = TRUE, #> legend.title = element_text(face = "bold")) ``` -------------------------------- ### ggcall() default and basic usage Source: https://dreamrs.github.io/esquisse/reference/ggcall.html Shows the default call and a call with data and aesthetic mappings. The output is shown as comments after each call. ```R # Default: ggcall() #> ggplot() # With data and aes ggcall("mtcars", list(x = "mpg", y = "wt")) #> ggplot(mtcars) + aes(x = mpg, y = wt) # Evaluate the call library(ggplot2) eval(ggcall("mtcars", list(x = "mpg", y = "wt"))) ``` -------------------------------- ### ggcall() with theme from other package Source: https://dreamrs.github.io/esquisse/reference/ggcall.html Uses a theme from another package by specifying the package name with ::. ```R # Theme from other package than ggplot2 ggcall( "mtcars", list(x = "mpg", y = "wt"), theme = "ggthemes::theme_economist" ) #> ggplot(mtcars) + aes(x = mpg, y = wt) + ggthemes::theme_economist() ``` -------------------------------- ### ggcall() with options Source: https://dreamrs.github.io/esquisse/reference/ggcall.html Demonstrates using multiple options: coord, labs, theme, facet, and theme_args. The output shows the combined ggplot call. ```R # With options ggcall( data = "mtcars", mapping = list(x = "hp", y = "cyl", fill = "color"), geom = "bar", coord = "flip", labs = list(title = "My title"), theme = "minimal", facet = c("gear", "carb"), theme_args = list(legend.position = "bottom") ) #> ggplot(mtcars) + aes(x = hp, y = cyl, fill = color) + geom_bar() + #> labs(title = "My title") + coord_flip() + theme_minimal() + #> theme(legend.position = "bottom") + facet_wrap(vars(gear, #> carb)) ``` -------------------------------- ### palettePicker Source: https://dreamrs.github.io/esquisse/reference/input-colors.html A select control for choosing a color palette. The source mentions this control but does not provide detailed usage examples. ```APIDOC ## palettePicker ### Description A select control for choosing a color palette. This control is mentioned in the source but no detailed usage examples are provided. ### Usage ```r palettePicker(...) ``` ### Parameters No parameters are documented in the source. ### Examples No examples are provided in the source. ``` -------------------------------- ### Save ggplot module: server-side usage with modal Source: https://dreamrs.github.io/esquisse/articles/shiny-usage.html Call the module from the server to display a modal window for saving a ggplot object. The example uses an actionButton to trigger the modal and passes a reactiveValues object with a 'plot' slot. ```R function(input, output, session) { observeEvent(input$save, { # actionButton to trigger modal save_ggplot_modal("ID", "Save plot") # launch modal }) save_ggplot_server("ID", rv) # rv is a reactiValues with a slot 'plot' } ``` -------------------------------- ### Launch esquisse addin Source: https://dreamrs.github.io/esquisse/ Launches the esquisse addin via esquisse::esquisser(), optionally with a data frame like palmerpenguins::penguins. ```r esquisse::esquisser() # or with your data: esquisse::esquisser(palmerpenguins::penguins) ``` -------------------------------- ### Load esquisse package Source: https://dreamrs.github.io/esquisse/articles/get-started.html Loads the esquisse package in an R session. This is the first step before using the addin. ```R library(esquisse) ``` -------------------------------- ### esquisse_ui() / esquisse_server() / esquisse_container() / esquisse_header() Source: https://dreamrs.github.io/esquisse/reference/index.html Esquisse module for Shiny applications. Provides UI and server functions to embed the esquisse interface in a Shiny app. ```APIDOC ## esquisse_ui() / esquisse_server() / esquisse_container() / esquisse_header() ### Description Esquisse module for Shiny applications. ### Functions - `esquisse_ui()`: UI function for the module. - `esquisse_server()`: Server function for the module. - `esquisse_container()`: Container for the module. - `esquisse_header()`: Header for the module. ``` -------------------------------- ### Call bs_theme_esquisse() Source: https://dreamrs.github.io/esquisse/reference/bs_theme_esquisse.html Returns a Bootstrap theme object created by bslib::bs_theme() for use with Esquisse. No arguments are required. ```r bs_theme_esquisse() ``` -------------------------------- ### bs_theme_esquisse() Source: https://dreamrs.github.io/esquisse/reference/bs_theme_esquisse.html Returns a Bootstrap theme object for use with Esquisse. This function takes no arguments and returns a bslib::bs_theme object. ```APIDOC ## bs_theme_esquisse() ### Description Returns a Bootstrap theme object for use with Esquisse. ### Usage ```r bs_theme_esquisse() ``` ### Value A `bslib::bs_theme()` object. ``` -------------------------------- ### Load esquisse and shiny libraries Source: https://dreamrs.github.io/esquisse/articles/shiny-usage.html Loads the required packages for using esquisse in a Shiny application. ```R library(shiny) library(esquisse) ``` -------------------------------- ### esquisse-package Source: https://dreamrs.github.io/esquisse/reference/index.html Explore and visualize your data interactively. The main package documentation. ```APIDOC ## esquisse-package ### Description Explore and visualize your data interactively. ### Usage ```r library(esquisse) ``` ``` -------------------------------- ### downloads_labels Source: https://dreamrs.github.io/esquisse/reference/ggplot-output.html Helper function to create labels for the export menu. Allows customization of labels for each export format. ```APIDOC ## downloads_labels ### Description Helper function to create labels for the export menu. Allows customization of labels for each export format. ### Usage ```r downloads_labels( label = ph("download-simple"), png = tagList(ph("image"), "PNG"), pdf = tagList(ph("file-pdf"), "PDF"), svg = tagList(ph("browsers"), "SVG"), jpeg = tagList(ph("image"), "JPEG"), pptx = tagList(ph("projector-screen"), "PPTX"), more = tagList(ph("gear"), i18n("More options")) ) ``` ### Arguments - **label** (character) - Optional - Main label for export button. - **png, pdf, svg, jpeg, pptx** (character) - Optional - Labels to display in export menu, use `NULL` to disable specific format. - **more** (character) - Optional - Label for "more" button, allowing to launch export modal. ### Value A list of labels for export options. ``` -------------------------------- ### Basic Shiny module usage with esquisse Source: https://dreamrs.github.io/esquisse/reference/esquisse-module.html A complete Shiny app that integrates the esquisse module. The UI includes a theme, radio buttons to select data (iris or mtcars), checkboxes for aesthetics, and the module UI. The server uses a reactiveValues object to hold the data and name, updates it based on the radio button, and calls esquisse_server with the data and reactive aesthetics. The module output is printed with str(). Note the output 'Loading required namespace: plotly' appears after the UI definition. ```r ### Part of a Shiny app ### library(shiny) library(esquisse) ui <- fluidPage( theme = bs_theme_esquisse(), tags$h1("Use esquisse as a Shiny module"), radioButtons( inputId = "data", label = "Data to use:", choices = c("iris", "mtcars"), inline = TRUE ), checkboxGroupInput( inputId = "aes", label = "Aesthetics to use:", choices = c( "fill", "color", "size", "shape", "weight", "group", "facet", "facet_row", "facet_col" ), selected = c("fill", "color", "size", "facet"), inline = TRUE ), esquisse_ui( id = "esquisse", header = FALSE, # dont display gadget title container = esquisse_container(height = "700px") ), tags$b("Output of the module:"), verbatimTextOutput("out") ) #> Loading required namespace: plotly server <- function(input, output, session) { data_rv <- reactiveValues(data = iris, name = "iris") observeEvent(input$data, { if (input$data == "iris") { data_rv$data <- iris data_rv$name <- "iris" } else { data_rv$data <- mtcars data_rv$name <- "mtcars" } }) esquisse_out <- esquisse_server( id = "esquisse", data_rv = data_rv, default_aes = reactive(input$aes) ) output$out <- renderPrint({ str(reactiveValuesToList(esquisse_out), max.level = 1) }) } if (interactive()) shinyApp(ui, server) ``` -------------------------------- ### build_aes function usage Source: https://dreamrs.github.io/esquisse/reference/build_aes.html The function signature for build_aes, showing the required data argument and optional ... , .list, and geom parameters. ```r build_aes(data, ..., .list = NULL, geom = NULL) ```