### 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")
)
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)
### 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(
theme = bs_theme_esquisse(),
esquisse_ui(
id = "esquisse",
header = esquisse_header(
close = FALSE, # hide the close button
.after = actionButton( # custom button
inputId = "open_modal",
label = NULL,
icon = icon("plus")
)
),
container = esquisse_container(fixed = TRUE),
play_pause = FALSE,
controls = c("settings", "labs", "axes", "geoms", "theme", "filters", "code", "export"),
layout_sidebar = TRUE
)
)
server <- function(input, output, session) {
esquisse_server(id = "esquisse")
observeEvent(input$open_modal, {
showModal(modalDialog("Some content"))
})
}
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",
theme = bs_theme_esquisse(),
tabPanel(
title = "esquisse",
esquisse_ui(
id = "esquisse",
header = FALSE,
container = esquisse_container(
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)
Run the code above in your browser using DataLab