library(shiny)
library(esquisse)

Use esquisse as a Shiny module

{esquisse} is built with Shiny modules (see this article for reference), so you can use {esquisse} directly into a Shiny application :

Result looks like :

The output of the module is a reactiveValues with 3 slots :

List of 3
 $ code_plot   : chr "ggplot(iris) + aes(x = Sepal.Length) + geom_histogram(bins = 30L, fill = \"#0c4c8a\") + theme_minimal()"
 $ code_filters:List of 2
  ..$ dplyr: language iris %>% filter(Petal.Length >= 1.45 & Petal.Length <= 6.9)
  ..$ expr : language Petal.Length >= 1.45 & Petal.Length <= 6.9
 $ data        :'data.frame':   126 obs. of  5 variables:
  ..$ Sepal.Length: num [1:126] 4.6 5.4 5 4.9 5.4 4.8 5.7 5.7 5.1 5.4 ...
  ..$ Sepal.Width : num [1:126] 3.1 3.9 3.4 3.1 3.7 3.4 4.4 3.8 3.8 3.4 ...
  ..$ Petal.Length: num [1:126] 1.5 1.7 1.5 1.5 1.5 1.6 1.5 1.7 1.5 1.7 ...
  ..$ Petal.Width : num [1:126] 0.2 0.4 0.2 0.1 0.2 0.2 0.4 0.3 0.3 0.2 ...
  ..$ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...

Other exported modules

Some modules used in {esquisse} are exported, so you can use them in your Shiny applications.

Filter data

Module to interactively filter a data.frame and retrieve the code :

Choose data

Module to interactively choose a data.frame in Global environment or to import an external file :

With an external file, import will be performed by package {rio} :

run_module("chooseData2")

Coerce variable

Coerce a variable from a class to another :

Input widgets

The drag-and-drop widget along with the button to select a geom are exported.

dropInput

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)