shinyobjects v0.1.1

0

Monthly downloads

0th

Percentile

Access Reactive Data Interactively

Troubleshooting reactive data in 'shiny' can be difficult. These functions will convert reactive data frames into functions and load all assigned objects into your local environment. If you create a dummy input object, as the function will suggest, you will be able to test your server and ui functions interactively.

Readme

shinyobjects

CRAN\_Status\_Badge CRAN
Downloads

Troubleshooting reactive data in a shiny app or flexdashboard can be difficult. The goal of this package is to access reactive objects in your local environment. This allows you to debug your code without having to actually run the app. It is my hope that this will save you time and allow you to iterate more quickly. The package converts reactive data frames into functions that will read from your raw data and become available in your environment. The main function will also recommended that you create a dummy input list in your script to simulate the reactive inputs. When you run the main function, load_reactive_objects(), it will prepopulate this list. You can learn more about dummy input lists in this vignette. The package also includes a function to view your UI elements in the viewer pane (see below).

Installation

You can install the released version of shinyobjects from CRAN with:

install.packages("shinyobjects")

You can install the development version from GitHub with:

devtools::install_github("rjake/shinyobjects")

Usage

There is a dummy flexdashboard available when the package is installed for you to see how this works.

library(shinyobjects)

# If the app is open, you can just run load_reactive_objects()
# The function will detect the app that is currently open
system.file(package = "shinyobjects", "Rmd/test_dashboard_no_inputs.Rmd") %>% 
 load_reactive_objects()

This will result in the following output

Here are the inputs you have listed:

  input_name  times_used  lines  missing
1      displ           1     45     TRUE
2       year           2  48,49     TRUE


Add this code chunk to your Rmd:
```{r input_demo, eval = FALSE}
input <- list(
  displ = "",
  year = ""
)
```

WARNING: This next step will load all object assignments into your environment.
Do you want to continue? 

1: Yes
2: No

Hitting 1 will then update your environment with all raw data and assignments, your dummy input list, and all reactive objects will be converted to functions. As functions, the code will keep all the data manipulation and reference your dummy input list. Note: this function does not change your files; the manipulation happens within the function.

There are additional arguments you can use to restart R or to clear the environment. The keep argument takes a regular expression as the pattern match. To get an exact match, use the ^ and $ to signify the beginning and end (ex. ^your_text$). To list objects, separate them with a |. as shown below.

load_reactive_objects(
  ...,
  clear_environment = TRUE, 
  keep = "test_|^df$|raw_data" # objects to keep
)

The package also has a function to view UI elements in one of two ways:

shiny::selectInput(
  "state",
  "Choose a state:",
  list(
    East = c("NY", "NJ", "CT"),
    West = c("WA", "OR", "CA"),
    Midwest = c("MN", "WI", "IA")
  )
)

# the output will automatically be used here
view_ui()

You can also pipe it

shiny::selectInput(
  "state",
  "Choose a state:",
  list(
    East = c("NY", "NJ", "CT"),
    West = c("WA", "OR", "CA"),
    Midwest = c("MN", "WI", "IA")
  )
) %>% view_ui(close_after = NULL)

Note that close_after is set to NULL in this example. The view_ui() function launches an app and defaults to closing after 5 seconds. You can adjusts how long it runs or use NULL and stop it manually by using the stop sign.:red_circle:

Functions in shinyobjects

Name Description
view_ui Show UI output in viewer pane
%>% Pipe operator
convert_selection Convert and load the highlighted assignment to your environment
load_reactive_objects Load inputs and convert reactive functions from an R/Rmd script to your environment
No Results!

Vignettes of shinyobjects

Name
tips-and-tricks.Rmd
No Results!

Last month downloads

Details

BugReports https://github.com/rjake/shinyobjects/issues
License GPL-3
Encoding UTF-8
LazyData true
RoxygenNote 7.1.0
VignetteBuilder knitr
Language en-US
NeedsCompilation no
Packaged 2020-06-26 20:00:03 UTC; foxtr
Repository CRAN
Date/Publication 2020-06-26 20:30:03 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/shinyobjects)](http://www.rdocumentation.org/packages/shinyobjects)