diff --git a/docs/404.html b/docs/404.html deleted file mode 100644 index f3664da4..00000000 --- a/docs/404.html +++ /dev/null @@ -1,171 +0,0 @@ - - - -
- - - - -YEAR: 2018 -COPYRIGHT HOLDER: dreamRs - -The esquisse package as a whole is distributed under GPL-3 (GNU GENERAL PUBLIC -LICENSE version 3). - - -The esquisse package includes other open source software components. The following -is a list of these components (full copies of the license agreements used by -these components are included below): - -- dragula, https://github.com/bevacqua/dragula -- clipboard.js, https://github.com/zenorocha/clipboard.js - - - - -Dragula license ---------------- - -The MIT License (MIT) - -Copyright © 2015-2016 Nicolas Bevacqua - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - - -clipboard.js license --------------------- - -The MIT License (MIT) -Copyright © 2018 Zeno Rocha <hi@zenorocha.com> - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - - - -- -
In RStudio, you can use the Addins menu :
- -Or in the R console :
-
-esquisser()
To use a data.frame
by default, if using the Addins menu highlight with the cursor a data.frame
in source editor before launching addin. Otherwise, pass the data.frame
as first argument to the function :
-esquisser(mtcars)
If you don’t have used a data.frame
when launching the addin, a window to import data will appear.
This feature comes from package {datamods}, you can find more documentation about it here.
- -This is the main interface and the most interesting part of the addin (in example below, we use penguins
dataset from {palmerpenguins}) :
You can select aesthetics to used by clicking the gear icon in top right corner, then drag-and-drop into aesthetics boxes to create a plot:
- -A geometry
is automatically picked to represent the data, according to data type. You can select an other geom
with button in top right corner :
Five menus under plot area are available to set plot parameters, filter data and retrieve code to generate the plot.
-This menu allow to set plot’s title, subtitle, caption, axis and aesthetics labels :
- -Here you can modify plot parameters, options available in the menu depends on type of plot :
- -Widgets to interactively filter data used in plot :
- -The filter module is available in package {datamods}.
-The code used to filter the data will be available in the following menu.
-You can save the plot created in various format by clicking the button in plot area’s top-right corner:
- -With “More options”, you can access a new window with more parameters to export the plot:
- -By default, esquisse is launched into a dialog window (if in RStudio), you can choose to use your browser if you prefer, or the Viewer pane.
- -You can set display mode with an option (in .Rprofile for example) :
-
-options("esquisse.viewer" = "browser")
{esquisse} is built with Shiny modules (see this article for reference), so you can use {esquisse} directly into a Shiny application :
-
-library(esquisse)
-library(shiny)
-library(ggplot2)
-
-ui <- fluidPage(
-
- titlePanel("Use esquisse as a Shiny module"),
-
- sidebarLayout(
- sidebarPanel(
- radioButtons(
- inputId = "data",
- label = "Select data to use:",
- choices = c("mpg", "diamonds", "economics")
- )
- ),
- mainPanel(
- tabsetPanel(
- tabPanel(
- title = "esquisse",
- esquisse_ui(
- id = "esquisse",
- header = FALSE # dont display gadget title
- )
- ),
- tabPanel(
- title = "output",
- tags$b("Code:"),
- verbatimTextOutput("code"),
- tags$b("Filters:"),
- verbatimTextOutput("filters"),
- tags$b("Data:"),
- verbatimTextOutput("data")
- )
- )
- )
- )
-)
-
-
-server <- function(input, output, session) {
-
- data_r <- reactiveValues(data = iris, name = "iris")
-
- observe({
- data_r$data <- get(input$data)
- data_r$name <- input$data
- })
-
- results <- esquisse_server(
- id = "esquisse",
- data_rv = data_r
- )
-
- output$code <- renderPrint({
- results$code_plot
- })
-
- output$filters <- renderPrint({
- results$code_filters
- })
-
- output$data <- renderPrint({
- str(results$data)
- })
-
-}
-
-shinyApp(ui, server)
Result looks like :
- -The output of the module is a reactiveValues
with 3 slots :
data.frame
used in plot (with filters applied).This modulle allow to save a ggplot
object in various format and to resize it before:
You can call the module from server to display it in a modal window (it’s also possible to display it directly in your UI):
-
-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'
-
-}
See ?"save-ggplot-module"
for complete example.
Add a menu to directly export plot, you can also launch module above for more controls (height, width, filename) by clicking “More options”:
- -
-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)
The drag-and-drop widget along with the button to select a geom and the color/palette picker are exported:
-
-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)
The widget used to select a geom in esquisser
addin. You can use images or icons for example:
-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)
A select menu to choose one or several colors:
-
-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)
A select menu to choose a color palette:
-
-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)
-- - -The purpose of this add-in is to let you explore your data quickly to extract the information they hold. You can create visualization with {ggplot2}, filter data with {dplyr} and retrieve generated code.
-
This addin allows you to interactively explore your data by visualizing it with the ggplot2 package. It allows you to draw bar plots, curves, scatter plots, histograms, boxplot and sf objects, then export the graph or retrieve the code to reproduce the graph.
-See online documentation : https://dreamrs.github.io/esquisse/index.html
-If you find bugs, please open an issue
-Install from CRAN with :
-
-install.packages("esquisse")
Or install development version from GitHub :
-
-remotes::install_github("dreamRs/esquisse")
Then launch the addin via the RStudio menu or with esquisse::esquisser()
.
NEWS.md
- save_ggplot_modal()
/ save_ggplot_ui()
: added output_format
argument to select the exported format allowed.dragulaInput()
/ updateDragulaInput()
with selected values.ggplot
and add export options: ggplot_output()
/ render_ggplot()
-save_ggplot_ui()
/ save_ggplot_server()
-geom_point
when plotting Time vs Continuous Data by @matton2
-updateDragulaInput()
to update dragulaInput()
server side.dragulaInput()
has two new arguments: ncolSource
and ncolGrid
to create a grid layout with source and targets boxes.dragulaInput
preventing to change variable in main addin.chooseDataServer()
has a new argument selectedTypes
to set types of variables selected by default. #95
-disable_filters
in esquisserUI()
to disable the ability to filter data.filterDF
.filterDF()
module handle missing values correctly.filterDF()
has two new arguments : drop_ids
: logical, drop or not column with only unique values, picker
allow to use shinyWidgets::pickerInput
.esquisseContainer()
to better integrate esquisse module in a shiny application.colorPicker()
and palettePicker()
to select a color or a palette (this is the select control used in the main addin).insert_code
in esquisserUI()
to hide “Insert into script button”.When using esquisse module into a shiny, it’s not necessary anymore to put esquisseUI
into a container, one is now added via argument esquisseUI(container = ...)
:
-
-# old
-tags$div(
- style = "height: 700px;",
- esquisserUI(
- id = "esquisse"
- )
-)
-
-# new
-esquisserUI(
- id = "esquisse",
- container = esquisseContainer(height = "700px")
-)
geom_smooth
).rlang
to generate ggplot code.dplyr
syntax. #19, #46
-scales
argument in facet_wrap
(fixed, free, free_x, free_y). #47
-viridisLite
.sf
objects.esquisse
as a shiny module.Build aesthetics to use in a plot
-build_aes(data, ..., .list = NULL, geom = NULL)- -
data | -Data to use in the plot. |
-
---|---|
... | -Named list of aesthetics. |
-
.list | -Alternative to |
-
geom | -Geom to use, according to the geom aesthetics may vary. |
-
An expression
- --# 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` -#> * `weight` -> `VAL`
Drag And Drop Input Widget
-dragulaInput( - inputId, - label = NULL, - sourceLabel, - targetsLabels, - targetsIds = NULL, - choices = NULL, - choiceNames = NULL, - choiceValues = NULL, - selected = NULL, - status = "primary", - replace = FALSE, - copySource = TRUE, - badge = TRUE, - ncolSource = "auto", - ncolGrid = NULL, - dragulaOpts = list(), - boxStyle = NULL, - width = NULL, - height = "100px" -)- -
inputId | -The |
-
---|---|
label | -Display label for the control, or |
-
sourceLabel | -Label display in the source box |
-
targetsLabels | -Labels for each target element. |
-
targetsIds | -Ids for retrieving values server-side, if |
-
choices | -List of values to select from (if elements of the list are
-named then that name rather than the value is displayed to the user).
-If this argument is provided, then |
-
choiceNames, choiceValues | -List of names and values, respectively, -that are displayed to the user in the app and correspond to the each -choice (for this reason, choiceNames and choiceValues must have the same length). -If either of these arguments is provided, then the other must be provided and -choices must not be provided. The advantage of using both of these over a named -list for choices is that choiceNames allows any type of UI object to be passed -through (tag objects, icons, HTML code, ...), instead of just simple text. |
-
selected | -Default selected values. Must be a |
-
status | -If choices are displayed into a Bootstrap label, you can use Bootstrap
-status to color them, or |
-
replace | -When a choice is dragged in a target container already -containing a choice, does the later be replaced by the new one ? |
-
copySource | -When |
-
badge | -Displays choices inside a Bootstrap badge. Use |
-
ncolSource | -Number of columns occupied by the source, default is |
-
ncolGrid | -Number of columns used to place source and targets boxes, see examples. |
-
dragulaOpts | -Options passed to dragula JavaScript library. |
-
boxStyle | -CSS style string to customize source and target container. |
-
width | -Width of the input. |
-
height | -Height of each boxes, the total input height is this parameter X 2. |
-
a UI definition
-The output server-side is a list with two slots: source
and targets
.
updateDragulaInput
to update choices server-side.
-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) - - -
A dropdown menu for selecting a value.
-dropInput( - inputId, - choicesNames, - choicesValues, - selected = NULL, - dropUp = FALSE, - dropWidth = NULL, - dropMaxHeight = NULL, - dropPreScrollable = FALSE, - btnClass = "btn-link", - width = NULL -)- -
inputId | -The |
-
---|---|
choicesNames | -A |
-
choicesValues | -Vector corresponding to |
-
selected | -The initial selected value, must be an element of |
-
dropUp | -Open the menu above the button rather than below. |
-
dropWidth | -Width of the dropdown menu. |
-
dropMaxHeight | -Maximal height for the menu. |
-
dropPreScrollable | -Force scroll bar to appear in the menu. |
-
btnClass | -Class for buttons in dropdown menu, default is |
-
width | -The width of the input. |
-
-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) - -} -
Use esquisse as a module in a Shiny application.
-esquisse_ui( - id, - header = TRUE, - container = esquisseContainer(), - controls = c("labs", "parameters", "appearance", "filters", "code"), - insert_code = FALSE -) - -esquisse_server( - id, - data_rv = NULL, - default_aes = c("fill", "color", "size", "group", "facet"), - import_from = c("env", "file", "copypaste", "googlesheets") -) - -esquisseContainer(width = "100%", height = "700px", fixed = FALSE)- -
id | -Module ID. |
-
---|---|
header | -Logical. Display or not |
-
container | -Container in which display the addin,
-default is to use |
-
controls | -Controls menu to be displayed. Use |
-
insert_code | -Logical, Display or not a button to insert the ggplot -code in the current user script (work only in RStudio). |
-
data_rv | -A |
-
default_aes | -Default aesthetics to be used, can be a |
-
import_from | -From where to import data, argument passed
-to |
-
width, height | -The width and height of the container, e.g. |
-
fixed | -Use a fixed container, e.g. to use use esquisse full page.
-If |
-
A reactiveValues
with 3 slots :
code_plot : code to generate plot.
code_filters : a list of length two with code to reproduce filters.
data : data.frame
used in plot (with filters applied).
--### Part of a Shiny app ### - -library(shiny) -library(esquisse) - -ui <- fluidPage( - 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 = esquisseContainer(height = "700px") - ) -) - -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_server( - id = "esquisse", - data_rv = data_rv, - default_aes = reactive(input$aes) - ) - -} - -if (interactive()) - shinyApp(ui, server) - - -### Whole Shiny app ### - -library(shiny) -library(esquisse) - - -# Load some datasets in app environment -my_data <- data.frame( - var1 = rnorm(100), - var2 = sample(letters[1:5], 100, TRUE) -) - - -ui <- fluidPage( - esquisse_ui( - id = "esquisse", - container = esquisseContainer(fixed = TRUE) - ) -) - -server <- function(input, output, session) { - - esquisse_server(id = "esquisse") - -} - -if (interactive()) - shinyApp(ui, server) - - - -## You can also use a vector of margins for the fixed argument, -# useful if you have a navbar for example - -library(shiny) -library(esquisse) -library(datamods) - -ui <- navbarPage( - title = "My navbar app", - tabPanel( - title = "esquisse", - esquisse_ui( - id = "esquisse", - header = FALSE, - container = esquisseContainer( - fixed = c(55, 0, 0, 0) - ) - ) - ) -) - -server <- function(input, output, session) { - - # lauch import data modal - import_modal( - id = "import-data", - from = c("env", "file", "copypaste"), - title = "Import data" - ) - data_imported_r <- datamods::import_server("import-data") - - data_rv <- reactiveValues(data = data.frame()) - observeEvent(data_imported_r$data(), { - data_rv$data <- data_imported_r$data() - data_rv$name <- data_imported_r$name() - }) - - esquisse_server(id = "esquisse", data_rv = data_rv) - -} - -if (interactive()) - shinyApp(ui, server) -
Select data to be used and map variables to aesthetics to produce a chart, -customize common elements and get code to reproduce the chart.
-esquisser( - data = NULL, - controls = c("labs", "parameters", "appearance", "filters", "code"), - viewer = getOption(x = "esquisse.viewer", default = "dialog") -)- -
data | -a |
-
---|---|
controls | -Controls menu to be displayed. Use |
-
viewer | -Where to display the gadget: |
-
NULL
. You can view code used to produce the chart, copy it or insert it in current script.
-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("esquisse.viewer" = "viewer") -# or -options("esquisse.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") - -} -
Generate code to create a ggplot2
ggcall( - data = NULL, - mapping = NULL, - geom = NULL, - geom_args = list(), - scales = NULL, - scales_args = list(), - coord = NULL, - labs = list(), - theme = NULL, - theme_args = list(), - facet = NULL, - facet_row = NULL, - facet_col = NULL, - facet_args = list(), - xlim = NULL, - ylim = NULL -)- -
data | -Character. Name of the |
-
---|---|
mapping | -List. Named list of aesthetics. |
-
geom | -Character. Name of the geom to use (with or without "geom_"). |
-
geom_args | -List. Arguments to use in the geom. |
-
scales | -Character vector. Scale(s) to use (with or without "scale_"). |
-
scales_args | -List. Arguments to use in scale(s),
-if |
-
coord | -Character. Coordinates to use (with or without "coord_"). |
-
labs | -List. Named list of labels to use for title, subtitle, x & y axis, legends. |
-
theme | -Character. Name of the theme to use (with or without "theme_"). |
-
theme_args | -Named list. Arguments for |
-
facet | -Character vector. Names of variables to use in |
-
facet_row | -Character vector. Names of row variables to use in |
-
facet_col | -Character vector. Names of col variables to use in |
-
facet_args | -Named list. Arguments for |
-
xlim | -A vector of length 2 representing limits on x-axis. |
-
ylim | -A vector of length 2 representing limits on y-axis. |
-
a call
that can be evaluated with eval
.
-# Default: -ggcall() -#> ggplot()#> ggplot(mtcars) + aes(x = mpg, y = wt)- -# With a geom: -ggcall( - data = "mtcars", - mapping = list(x = "mpg", y = "wt"), - geom = "point" -) -#> ggplot(mtcars) + aes(x = mpg, y = wt) + geom_point()-# 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))-# 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"))-# 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()- -# One scale -ggcall( - data = "mtcars", - mapping = list(x = "mpg", y = "wt", color = "qsec"), - geom = "point", - scales = "color_distiller", - scales_args = list(palette = "Blues") -) -#> ggplot(mtcars) + aes(x = mpg, y = wt, color = qsec) + geom_point() + -#> scale_color_distiller(palette = "Blues")-# Two scales -ggcall( - data = "mtcars", - mapping = list(x = "mpg", y = "wt", color = "qsec", size = "qsec"), - geom = "point", - scales = c("color_distiller", "size_continuous"), - scales_args = list( - color_distiller = list(palette = "Greens"), - size_continuous = list(range = c(1, 20)) - ) -) -#> ggplot(mtcars) + aes(x = mpg, y = wt, color = qsec, size = qsec) + -#> geom_point() + scale_color_distiller(palette = "Greens") + -#> scale_size_continuous(range = c(1, 20))
Display a plot on the client and allow to download it.
-ggplot_output( - id, - width = "100%", - height = "400px", - downloads = downloads_labels(), - ... -) - -downloads_labels( - label = icon("download"), - png = tagList(icon("file-image-o"), "PNG"), - pdf = tagList(icon("file-pdf-o"), "PDF"), - svg = tagList(icon("chrome"), "SVG"), - jpeg = tagList(icon("file-image-o"), "JPEG"), - pptx = tagList(icon("file-powerpoint-o"), "PPTX"), - more = tagList(icon("gear"), "More options") -) - -render_ggplot( - id, - expr, - ..., - env = parent.frame(), - quoted = FALSE, - filename = "export-ggplot" -)- -
id | -Module ID. |
-
---|---|
width | -Width of the plot. |
-
height | -Height of the plot. |
-
downloads | -Labels for export options, use |
-
... | -Parameters passed to |
-
label | -Main label for export button |
-
png, pdf, svg, jpeg, pptx | -Labels to display in
-export menu, use |
-
more | -Label for "more" button, allowing to launch export modal. |
-
expr | -An expression that generates a |
-
env | -The environment in which to evaluate expression. |
-
quoted | -Is |
-
filename | -A string of the filename to export WITHOUT extension, -it will be added according to type of export. |
-
Server-side, a reactiveValues
with the plot.
--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) -
You can use the RStudio addin to interactively select ggplot objects, or -directly pass their names to the function.
-ggplot_to_ppt(gg = NULL)- -
gg | -character. Name(s) of ggplot object(s), if NULL, launch the Shiny gadget. |
-
---|
Path to the temporary PowerPoint file.
- ---# 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") - -} - -
- All functions- - |
- |
---|---|
- - | -Build aesthetics to use in a plot |
-
- - | -Drag And Drop Input Widget |
-
- - | -Dropdown Input |
-
- - | -Deprecated functions |
-
- - | -Esquisse module |
-
- - | -An add-in to easily create plots with ggplot2 |
-
- - | -Generate code to create a |
-
- - | -Render |
-
- - | -Utility to export ggplot objects to PowerPoint |
-
-
|
- Picker input to select color(s) or palette |
-
- - | -Match list of arguments to arguments of geometry |
-
- - | -Module for choosing data.frame |
-
- - | -Coerce data.frame's columns module |
-
- - | -Esquisse Shiny module |
-
- - | -Shiny module to interactively filter a |
-
- - | -Potential geometries according to the data |
-
- - | -Run module example |
-
- - | -Safely render a |
-
- - | -Save |
-
- - | -Update Dragula Input |
-
- - | -Change the value of a drop input on the client |
-
- - | -Automatically select appropriate color scale |
-
Select menu to view and choose a color or a palette of colors.
-colorPicker( - inputId, - label, - choices, - selected = NULL, - textColor = "#000", - plainColor = FALSE, - multiple = FALSE, - pickerOpts = list(), - width = NULL -) - -updateColorPicker( - session = getDefaultReactiveDomain(), - inputId, - choices, - textColor = "#000", - plainColor = FALSE, - multiple = FALSE -) - -palettePicker( - inputId, - label, - choices, - selected = NULL, - textColor = "#000", - plainColor = FALSE, - pickerOpts = list(), - width = NULL -) - -updatePalettePicker( - session = getDefaultReactiveDomain(), - inputId, - choices, - selected = NULL, - textColor = "#000", - plainColor = FALSE -)- -
inputId | -The |
-
---|---|
label | -Display label for the control, or |
-
choices | -List of values to select from. Values must be valid Hex colors. -If elements of the list are named then that name rather than the value is displayed to the user. |
-
selected | -The initially selected value (or multiple values if |
-
textColor | -Color of the text displayed above colors, can be a vector of the same length as choices. |
-
plainColor | -Color the full space of the choice menu. |
-
multiple | -Is selection of multiple items allowed? |
-
pickerOpts | -Options for |
-
width | -The width of the input : |
-
session | -Shiny session. |
-
A select control that can be added to a UI definition.
- ---# 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) -} - -# palettePicker ----------------------------------------------------------- - -library(shiny) -library(esquisse) -library(scales) - -ui <- fluidPage( - tags$h2("pickerColor examples"), - - fluidRow( - column( - width = 4, - palettePicker( - inputId = "pal1", - label = "Select a palette:", - choices = list( - "Blues" = brewer_pal(palette = "Blues")(8), - "Reds" = brewer_pal(palette = "Reds")(8) - ) - ), - verbatimTextOutput("res1"), - palettePicker( - inputId = "pal4", - label = "Update palette:", - choices = list( - "Blues" = brewer_pal(palette = "Blues")(8), - "Reds" = brewer_pal(palette = "Reds")(8) - ) - ), - verbatimTextOutput("res4"), - radioButtons( - "update", "Palettes:", c("default", "viridis", "brewer"), - inline = TRUE - ) - ), - column( - width = 4, - palettePicker( - inputId = "pal2", - label = "With a list of 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("res2") - ), - column( - width = 4, - palettePicker( - inputId = "pal3", - label = "With plain colors:", - choices = list( - "BrBG" = brewer_pal(palette = "BrBG")(8), - "PiYG" = brewer_pal(palette = "PiYG")(8), - "PRGn" = brewer_pal(palette = "PRGn")(8), - "PuOr" = brewer_pal(palette = "PuOr")(8), - "RdBu" = brewer_pal(palette = "RdBu")(8), - "RdGy" = brewer_pal(palette = "RdGy")(8), - "RdYlBu" = brewer_pal(palette = "RdYlBu")(8), - "RdYlGn" = brewer_pal(palette = "RdYlGn")(8), - "Spectral" = brewer_pal(palette = "Spectral")(8) - ), - plainColor = TRUE, - textColor = "white" - ), - verbatimTextOutput("res3") - ) - ) -) - -server <- function(input, output, session) { - - output$res1 <- renderPrint(input$pal1) - output$res2 <- renderPrint(input$pal2) - output$res3 <- renderPrint(input$pal3) - output$res4 <- renderPrint(input$pal4) - - observeEvent(input$update, { - if (input$update == "default") { - updatePalettePicker( - inputId = "pal4", - choices = list( - "Blues" = brewer_pal(palette = "Blues")(8), - "Reds" = brewer_pal(palette = "Reds")(8) - ) - ) - } else if (input$update == "viridis") { - updatePalettePicker( - inputId = "pal4", - choices = 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) - ), - textColor = "#FFF" - ) - } else if (input$update == "brewer") { - updatePalettePicker( - inputId = "pal4", - choices = 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) - ) - ) - } - }) -} - -if (interactive()) { - shinyApp(ui, server) -} -
Match list of arguments to arguments of geometry
-match_geom_args( - geom, - args, - add_aes = TRUE, - mapping = list(), - envir = "ggplot2" -)- -
geom | -Character. name of the geometry. |
-
---|---|
args | -Named list, parameters to be matched to the geometry arguments. |
-
add_aes | -Add aesthetics parameters (like size, fill, ...). |
-
mapping | -Mapping used in plot, to avoid setting fixed aesthetics parameters. |
-
envir | -Package environment to search in. |
-
a list
-# 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 -#> -#> $fill -#> [1] "#112246" -#>match_geom_args(geom = "violin", args = params) -#> $scale -#> [1] "width" -#> -#> $adjust -#> [1] 2 -#> -#> $fill -#> [1] "#112246" -#>match_geom_args(geom = "bar", args = params, add_aes = FALSE) -#> named list()match_geom_args(geom = "point", args = params) -#> $size -#> [1] 1.6 -#> -#> $fill -#> [1] "#112246" -#>match_geom_args(geom = "point", args = params, add_aes = FALSE) -#> named list()
DEPRECATED, please see package datamods for similar features.
-chooseDataUI(id, label = "Data", icon = "database", width = "100%", ...) - -chooseDataServer( - input, - output, - session, - dataModule = c("GlobalEnv", "ImportFile"), - data = NULL, - name = NULL, - selectVars = TRUE, - selectedTypes = c("continuous", "discrete", "time"), - coerceVars = FALSE, - launchOnStart = TRUE, - size = "m" -)- -
id | -Module's id. |
-
---|---|
label | -Label for button, passed to |
-
icon | -Icon to appears on the button, passed to |
-
width | -Width of button, passed to |
-
... | -Other arguments passed to |
-
input, output, session | -standards |
-
dataModule | -Data module to use, choose between |
-
data | -A |
-
name | -Character, object's name to use for |
-
selectVars | -Display module to select variables, |
-
selectedTypes | -Type of variables selected by default in select variables module.
-Possible types are |
-
coerceVars | -Display module to coerce variables between different class, |
-
launchOnStart | -Opens modal window when the application starts. |
-
size | -Size for the modal window. |
-
a reactiveValues
containing the data selected under slot data
-and the name of the selected data.frame
under slot name
.
DEPRECATED, please see package datamods for similar features.
-coerceUI(id) - -coerceServer(input, output, session, data, reactiveValuesSlot = "data")- -
id | -Module id. See |
-
---|---|
input, output, session | -standards |
-
data | -A |
-
reactiveValuesSlot | -If |
-
a reactiveValues
with two slots: data
original data.frame
-with modified columns, and names
column's names with call to coerce method.
DEPRECATED, see esquisse-module
.
esquisserServer( - input, - output, - session, - data = NULL, - dataModule = c("GlobalEnv", "ImportFile"), - sizeDataModule = "m" -) - -esquisserUI( - id, - header = TRUE, - container = esquisseContainer(), - choose_data = TRUE, - insert_code = FALSE, - disable_filters = FALSE -)- -
input, output, session | -Standards |
-
---|---|
data | -A |
-
dataModule | -Data module to use, choose between |
-
sizeDataModule | -Size for the modal window for selecting data. |
-
id | -Module's id. |
-
header | -Logical. Display or not |
-
container | -Container in which display the addin,
-default is to use |
-
choose_data | -Logical. Display or not the button to choose data. |
-
insert_code | -Logical, Display or not a button to insert the ggplot -code in the current user script (work only in RStudio). |
-
disable_filters | -Logical. Disable the menu allowing to filter data used. |
-
A reactiveValues
with 3 slots :
code_plot : code to generate plot.
code_filters : a list of length two with code to reproduce filters.
data : data.frame
used in plot (with filters applied).
For the module to display correctly, it is necessary to place -it in a container with a fixed height. Since version >= 0.2.2, the -container is added by default.
- -DEPRECATED, please see package datamods for similar features.
-filterDF_UI(id, show_nrow = TRUE) - -filterDF( - input, - output, - session, - data_table = reactive(), - data_vars = shiny::reactive(NULL), - data_name = reactive("data"), - label_nrow = "Number of rows:", - drop_ids = TRUE, - picker = FALSE -)- -
id | -Module id. See |
-
---|---|
show_nrow | -Show number of filtered rows and total. |
-
input, output, session | -standards |
-
data_table | -
|
-
data_vars | -
|
-
data_name | -
|
-
label_nrow | -Text to display before the number of rows of filtered data / source data. |
-
drop_ids | -Drop columns containing more than 90% of unique values, or than 50 distinct values. |
-
picker | -Use |
-
A list
with 2 elements :
data_filtered : reactive
function returning data filtered.
code : reactiveValues
with 2 slots :
-expr
(raw expression to filter data) and dplyr
(code with dplyr pipeline).
Potential geometries according to the data
-potential_geoms(data, mapping, auto = FALSE)- -
data | -A |
-
---|---|
mapping | -List of aesthetic mappings to use with data. |
-
auto | -Return only one geometry. |
-
A character
vector
--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"#> [1] "bar"-# Two continuous variables -potential_geoms( - data = iris, - mapping = aes(x = Sepal.Length, y = Sepal.Width) -) -#> [1] "point" "line" "step" "area" "tile"
Safely render a ggplot
in Shiny application
safe_ggplot(expr, data = NULL, session = shiny::getDefaultReactiveDomain())- -
expr | -Code to produce a |
-
---|---|
data | -Argument passed to |
-
session | -Session object to send notification to. |
-
Output of ggplot_build
.
-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) -} -
Save a ggplot
object in various format and resize it before saving.
save_ggplot_ui( - id, - output_format = c("png", "pdf", "svg", "jpeg", "bmp", "eps", "tiff") -) - -save_ggplot_modal( - id, - title = NULL, - output_format = c("png", "pdf", "svg", "jpeg", "bmp", "eps", "tiff") -) - -save_ggplot_server(id, plot_rv)- -
id | -Module ID. |
-
---|---|
output_format | -Output formats offered to the user. |
-
title | -Modal's title. |
-
plot_rv | -A |
-
No value. Use in UI & server of shiny application.
- --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) -
Update Dragula Input
-updateDragulaInput( - session, - inputId, - choices = NULL, - choiceNames = NULL, - choiceValues = NULL, - selected = NULL, - selectedNames = NULL, - selectedValues = NULL, - badge = TRUE, - status = "primary" -)- -
session | -The |
-
---|---|
inputId | -The id of the input object. |
-
choices | -List of values to select from (if elements of the list are
-named then that name rather than the value is displayed to the user).
-If this argument is provided, then |
-
choiceNames, choiceValues | -List of names and values, respectively, -that are displayed to the user in the app and correspond to the each -choice (for this reason, choiceNames and choiceValues must have the same length). -If either of these arguments is provided, then the other must be provided and -choices must not be provided. The advantage of using both of these over a named -list for choices is that choiceNames allows any type of UI object to be passed -through (tag objects, icons, HTML code, ...), instead of just simple text. |
-
selected | -A |
-
selectedNames, selectedValues | -Update selected items with custom names and values. |
-
badge | -Displays choices inside a Bootstrap badge. |
-
status | -If choices are displayed into a Bootstrap badge, you can use Bootstrap
-status to color them, or |
-
--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) - -} - -
Change the value of a drop input on the client
-updateDropInput(session, inputId, selected = NULL, disabled = NULL)- -
session | -The |
-
---|---|
inputId | -The id of the input object. |
-
selected | -The initially selected value. |
-
disabled | -Choices ( |
-
-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) - -} -
Automatically select appropriate color scale
-which_pal_scale( - mapping, - palette = "ggplot2", - data = NULL, - fill_type = c("continuous", "discrete"), - color_type = c("continuous", "discrete"), - reverse = FALSE -)- -
mapping | -Aesthetics used in |
-
---|---|
palette | -Color palette. |
-
data | -An optional |
-
fill_type, color_type | -Scale to use according to the variable used
-in |
-
reverse | -Reverse colors order or not. |
-
a list
-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() -#>#> $scales -#> [1] "scale_fill_hue" -#> -#> $args -#> $args$scale_fill_hue -#> $args$scale_fill_hue$direction -#> [1] 1 -#> -#> -#>- -# 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 -#> -#> -#>- -# 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 -#> -#> -#>