Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions R/visconfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@
#' @param session The shiny session object.
#'
#' @return No return value. The result will be available on the client side.
#'
#' @examples
#' # A simple Shiny app that prints the exported config
#' library(shiny)
#' library(GWalkR)
#' data(mtcars)
#'
#' ui <- fluidPage(
#' gwalkrOutput("gw"),
#' actionButton("save", "Save Viz"),
#' verbatimTextOutput("config")
#' )
#'
#' server <- function(input, output, session) {
#' output$gw <- renderGwalkr(gwalkr(mtcars))
#'
#' observeEvent(input$save, request_vis_config("gw"))
#'
#' output$config <- renderText({ input$gw_visConfig })
#' }
#'
#' if (interactive()) shinyApp(ui, server)
#'
#' @export
request_vis_config <- function(id, session = shiny::getDefaultReactiveDomain()) {
if (is.null(session)) {
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ Showcase your data insights with editable and explorable charts on a webpage ([e

<img width="700" alt="image" src="https://github.com/bruceyyu/GWalkR/assets/33870780/4798367c-0dd4-4ad3-b25b-7ea48b79205a">

### Save and restore visualizations in Shiny

Use `request_vis_config()` to programmatically export the current visualization configuration from a `gwalkr` widget. The snippet below prints the JSON after clicking **Save Viz**.

```R
library(shiny)
library(GWalkR)
data(mtcars)

ui <- fluidPage(
gwalkrOutput("gw"),
actionButton("save", "Save Viz"),
verbatimTextOutput("config")
)

server <- function(input, output, session) {
output$gw <- renderGwalkr(gwalkr(mtcars))
observeEvent(input$save, request_vis_config("gw"))
output$config <- renderText({ input$gw_visConfig })
}

if (interactive()) shinyApp(ui, server)
```

See `inst/examples/export_vis_config/app.R` for a complete example.

## Development
We encourage developers from the amazing open-source community to help improve this R package!

Expand Down
23 changes: 23 additions & 0 deletions inst/examples/export_vis_config/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
library(shiny)
library(GWalkR)

data(mtcars)

ui <- fluidPage(
titlePanel("Export GWalkR Configuration"),
gwalkrOutput("gw", height = "600px"),
actionButton("save", "Save Viz"),
verbatimTextOutput("config")
)

server <- function(input, output, session) {
output$gw <- renderGwalkr(gwalkr(mtcars))

observeEvent(input$save, request_vis_config("gw"))

output$config <- renderText({
input$gw_visConfig
})
}

shinyApp(ui, server)
20 changes: 20 additions & 0 deletions man/request_vis_config.Rd

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