Skip to content

Commit

Permalink
Use 'getDefaultReactiveDomain()' when there is no 'session' argument …
Browse files Browse the repository at this point in the history
…provided to 'shinyURL.server()'
  • Loading branch information
aoles committed Jan 25, 2016
1 parent 77ca91a commit 956a884
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: shinyURL
Type: Package
Title: Save and restore the state of Shiny apps
Version: 0.0.22
Version: 0.0.23
Encoding: UTF-8
Author: Andrzej Oleś
Maintainer: Andrzej Oleś <[email protected]>
Description: Save and restore the state of a Shiny app's widgets by encoding
them in an URL query string.
Description: Save and restore the view state of a Shiny app by encoding the
values of user inputs and active tab panels in the app's URL query string.
Imports:
RCurl,
shiny (>= 0.12.0),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ importFrom(RCurl,getURL)
importFrom(shiny,actionButton)
importFrom(shiny,div)
importFrom(shiny,eventReactive)
importFrom(shiny,getDefaultReactiveDomain)
importFrom(shiny,icon)
importFrom(shiny,includeScript)
importFrom(shiny,invalidateLater)
Expand Down
20 changes: 13 additions & 7 deletions R/shinyURL.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#' Save and restore the state of Shiny app's widgets
#'
#' Encode the state of Shiny app's widgets into an URL query string, and use
#' Encode the state of Shiny app's widgets into an URL query string, and use
#' parameters from the URL query string to initialize the applications.
#'
#' @section Quick setup: To start using shinyURL in your Shiny app, follow these
#' three steps: \enumerate{ \item Load the package in both 'server.R' an
#' 'ui.R': \code{library("shinyURL")} \item Add a call to \code{
#' three steps: \enumerate{ \item Load the package in both 'server.R' an
#' 'ui.R': \code{library("shinyURL")} \item Add a call to \code{
#' shinyURL.server(session)} inside the 'shinyServer' function in 'server.R',
#' where `session` is the argument passed to the server function. \item Add
#' where `session` is the argument passed to the server function. \item Add
#' the \code{shinyURL.ui()} widget to 'ui.R'. }
#' @author Andrzej Oleś <andrzej.oles@@embl.de>
#' @examples
Expand Down Expand Up @@ -47,9 +47,11 @@
#'
#' }
#' @name shinyURL
#' @importFrom shiny isolate observe parseQueryString observeEvent
#' @importFrom shiny isolate observe parseQueryString observeEvent
#' updateTextInput eventReactive reactiveValuesToList invalidateLater
#' @importFrom shiny tagList tags icon includeScript actionButton div validateCssUnit
#' getDefaultReactiveDomain
#' @importFrom shiny tagList tags icon includeScript actionButton div
#' validateCssUnit
#' @importFrom RCurl getURL
#' @importFrom utils URLencode
NULL
Expand All @@ -59,10 +61,14 @@ inputId=".shinyURL"
#' @details The \code{shinyURL.server} method contains server logic for encoding
#' and restoring the widgets' state. It is called from inside the app's server
#' function with the \code{session} argument.
#' @param session Parameter passed from the Shiny server function
#' ).
#' @param session typically the same as the optional parameter passed into the Shiny server function as an argument; if missing defaults to \code{getDefaultReactiveDomain()}
#' @rdname shinyURL
#' @export
shinyURL.server = function(session) {
if (missing(session))
session = getDefaultReactiveDomain()

queryValues <- isolate(parseQueryString(session$clientData$url_search, nested=TRUE))

## initialize from query string
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@

## Use

1. Load the package in both **server.R** and **ui.R**:
1. Load the package in both **server.R** and **ui.R**.

library("shinyURL")

2. In **server.R**, add a call to
2. In **server.R**, add inside the server function a call to

shinyURL.server(session)
shinyURL.server()

inside the `shinyServer` function, where `session` is the argument passed to the server function.
where `session` is the argument passed to the server function.

3. Add the shinyURL widget to **ui.R**:
3. Add the shinyURL widget to **ui.R**.

shinyURL.ui()
## Restoring tabset and navbar panels
### Restoring of tabset and navbar panels

To save and restore active tabs provide the `id` argument to the functions `tabsetPanel` or `navbarPage`.

### Disable encoding of certain inputs

You can suppress certain inputs from being encoded in the query URL by using IDs with a leading dot, e.g. `.inputName`. These inputs won't be restored.

## Limitations

### Long URLs
Expand All @@ -47,6 +51,3 @@ These points are especially relevant for apps with lots of controls.

Unfortunately, operations performed using action buttons cannot be reliably recorded and restored.

### Disable encoding of certain inputs

You can suppress certain inputs from being encoded in the query URL by using IDs with a leading dot, e.g. `.inputName`. These inputs won't be restored.
11 changes: 6 additions & 5 deletions man/shinyURL.Rd

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

0 comments on commit 956a884

Please sign in to comment.