Skip to content

Commit

Permalink
esquisse_ui(): ability to display not element of the module (header's…
Browse files Browse the repository at this point in the history
… button, play/pause button, export options)
  • Loading branch information
pvictor committed Oct 20, 2023
1 parent 9aaaff8 commit 94dc1a0
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 47 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: esquisse
Type: Package
Title: Explore and Visualize Your Data Interactively
Version: 1.1.2.9500
Version: 1.1.2.9600
Authors@R: c(person("Fanny", "Meyer", role = c("aut")),
person("Victor", "Perrier", email = "victor.perrier@dreamrs.fr", role = c("aut", "cre")),
person("Ian", "Carroll", comment = "Faceting support", role = "ctb"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ importFrom(rlang,eval_tidy)
importFrom(rlang,expr)
importFrom(rlang,has_length)
importFrom(rlang,is_call)
importFrom(rlang,is_list)
importFrom(rlang,is_named)
importFrom(rlang,parse_expr)
importFrom(rlang,sym)
Expand Down Expand Up @@ -205,4 +206,5 @@ importFrom(tools,toTitleCase)
importFrom(utils,browseURL)
importFrom(utils,data)
importFrom(utils,head)
importFrom(utils,modifyList)
importFrom(utils,packageVersion)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* `esquisse_server()` : support for reactive functions for `data_rv` argument.
* Allow `esquisse_server()` to be initialized with NULL without forcing the import module to appear using `import_from = NULL` [#232](https://github.com/dreamRs/esquisse/issues/232).
* New geom available in the interface : `geom_path`.
* `esquisse_ui()`: ability to display not element of the module (header's button, play/pause button, export options).

* i18n: new translations added:
+ polish, activate with `set_i18n("pl")`, thanks to [@jakub-jedrusiak](https://github.com/jakub-jedrusiak)
Expand Down
79 changes: 49 additions & 30 deletions R/esquisse-ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
#' @description Use esquisse as a module in a Shiny application.
#'
#' @param id Module ID.
#' @param header Logical. Display or not `esquisse` header.
#' @param header Either `TRUE` or `FALSE` to display or not `esquisse` header, or a named `list`
#' where names are : `settings`, `close`, `import` and `show_data` and values are `TRUE` or
#' `FALSE` to display or not the corresponding button.
#' @param container Container in which display the addin,
#' default is to use `esquisseContainer`, see examples.
#' Use `NULL` for no container (behavior in versions <= 0.2.1).
#' Must be a `function`.
#' @param controls Controls menu to be displayed. Use `NULL` to hide all menus.
#' @param insert_code Logical, Display or not a button to insert the ggplot
#' code in the current user script (work only in RStudio).
#' @param play_pause Display or not the play / pause button.
#' @param downloads Export options available or `NULL` for no export. See [downloads_labels()].
#'
#' @return A `reactiveValues` with 3 slots :
#' * **code_plot** : code to generate plot.
Expand All @@ -27,6 +31,8 @@
#' @importFrom htmltools tags tagList
#' @importFrom shiny fillPage plotOutput actionButton NS fluidRow column fillCol
#' @importFrom shinyWidgets prettyToggle
#' @importFrom rlang is_list
#' @importFrom utils modifyList
#'
#' @example examples/esquisse-module-1.R
#'
Expand All @@ -37,46 +43,58 @@ esquisse_ui <- function(id,
header = TRUE,
container = esquisseContainer(),
controls = c("labs", "parameters", "appearance", "filters", "code"),
insert_code = FALSE) {
insert_code = FALSE,
play_pause = TRUE,
downloads = downloads_labels()) {
ns <- NS(id)
header_btns <- list(settings = TRUE, close = TRUE, import = TRUE, show_data = TRUE)
if (is_list(header)) {
header_btns <- modifyList(header_btns, header)
header <- TRUE
}
tag_header <- tags$div(
class = "esquisse-title-container",
tags$h1("Esquisse", class = "esquisse-title"),
tags$div(
class = "pull-right float-end",
actionButton(
inputId = ns("settings"),
label = ph("gear-six", height = "2em", title = i18n("Display settings")),
class = "btn-sm",
title = i18n("Display settings")
),
actionButton(
inputId = ns("close"),
label = ph("x", height = "2em", title = i18n("Close Window")),
class = "btn-sm",
title = i18n("Close Window")
)
if (isTRUE(header_btns$settings)) {
actionButton(
inputId = ns("settings"),
label = ph("gear-six", height = "2em", title = i18n("Display settings")),
class = "btn-sm",
title = i18n("Display settings")
)
},
if (isTRUE(header_btns$close)) {
actionButton(
inputId = ns("close"),
label = ph("x", height = "2em", title = i18n("Close Window")),
class = "btn-sm",
title = i18n("Close Window")
)
}
),
tags$div(
class = "pull-left",
actionButton(
inputId = ns("launch_import_data"),
label = ph("database", height = "2em", title = i18n("Import data")),
class = "btn-sm",
title = i18n("Import data")
),
show_data_ui(ns("show_data"))
if (isTRUE(header_btns$import)) {
actionButton(
inputId = ns("launch_import_data"),
label = ph("database", height = "2em", title = i18n("Import data")),
class = "btn-sm",
title = i18n("Import data")
)
},
if (isTRUE(header_btns$show_data)) show_data_ui(ns("show_data"))
)
)

ui <- tags$div(
class = "esquisse-container",
html_dependency_esquisse(),
html_dependency_clipboard(),
# shinyWidgets::chooseSliderSkin("Modern", "#112446"),


if (isTRUE(header)) tag_header,

tags$div(
class = "esquisse-geom-aes",
tags$div(
Expand All @@ -91,27 +109,28 @@ esquisse_ui <- function(id,
),
select_aes_ui(ns("aes"))
),

fillCol(
style = "overflow-y: auto;",
tags$div(
style = "height: 100%; min-height: 400px; overflow: hidden;",
play_pause_input(ns("play_plot")),
play_pause_input(ns("play_plot"), show = play_pause),
ggplot_output(
id = ns("plooooooot"),
width = "100%",
height = "100%"
height = "100%",
downloads = downloads
)
)
),

controls_ui(
id = ns("controls"),
insert_code = insert_code,
controls = controls
)
)

if (is.function(container)) {
ui <- container(ui)
}
Expand Down
2 changes: 1 addition & 1 deletion R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ save_ggplot_server <- function(id, plot_rv) {
#' @param id Module ID.
#' @param width Width of the plot.
#' @param height Height of the plot.
#' @param downloads Labels for export options, use `downloads_labels`.
#' @param downloads Labels for export options, use `downloads_labels()` or `NULL` to disable export options.
#' @param ... Parameters passed to [shiny::plotOutput()] (`ggplot_output`) or [shiny::renderPlot()] (`render_ggplot`).
#'
#' @return Server-side, a `reactiveValues` with the plot.
Expand Down
16 changes: 12 additions & 4 deletions R/utils-shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ rCodeContainer <- function(...) {
}


play_pause_input <- function(inputId) {
play_pause <- shinyWidgets::prettyToggle(
#' @importFrom shinyWidgets prettyToggle
#' @importFrom htmltools css
play_pause_input <- function(inputId, show = TRUE) {
play_pause <- prettyToggle(
inputId = inputId,
value = TRUE,
label_on = "Play",
Expand All @@ -122,8 +124,14 @@ play_pause_input <- function(inputId) {
)
play_pause$attribs$style <- "display: inline-block; margin-right: -5px;"
tags$div(
# style = "position: absolute; right: 0; top: 35px; font-weight: bold; z-index: 1000;",
style = "position: absolute; right: 40px; top: 5px; font-weight: bold; z-index: 1000;",
style = css(
position = "absolute",
right = "40px",
top = "5px",
fontWeight = "bold",
zIndex = 1000,
display = if (!isTRUE(show)) "none"
),
class = "esquisse-playpause-btn",
play_pause
)
Expand Down
10 changes: 6 additions & 4 deletions examples/esquisse-module-2.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ my_data <- data.frame(

ui <- fluidPage(
esquisse_ui(
id = "esquisse",
container = esquisseContainer(fixed = TRUE)
id = "esquisse",
header = list(close = FALSE), # hide the close button
container = esquisseContainer(fixed = TRUE),
play_pause = FALSE
)
)

server <- function(input, output, session) {

esquisse_server(id = "esquisse")

}

if (interactive())
Expand Down
22 changes: 16 additions & 6 deletions man/esquisse-module.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ggplot-output.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 94dc1a0

Please sign in to comment.