Skip to content

Latest commit

 

History

History
91 lines (68 loc) · 3.16 KB

README.md

File metadata and controls

91 lines (68 loc) · 3.16 KB

shinyenv

Lifecycle: experimental CRAN status Codecov test coverage R-CMD-check

An experimental package to deal with environment-like variables in Shiny.

Installation

You can install the development version of shinyenv from GitHub with:

# install.packages("pak")
pak::pak("shinyworks/shinyenv")

Alternatively, you can use the functions without taking a dependency on {shinyenv}:

# install.packages("usethis")
usethis::use_standalone("shinyworks/shinyenv", "envvars")

Usage

You probably shouldn’t use this package.

You might see advice to use session$userData or other techniques to break out of the module straitjacket. Be wary of such advice: it’s showing you how to work around the rules imposed by namespacing, making it easy to re-introduce much complexity to your app and significantly reducing the benefits of using a module in the first place.
– Hadley Wickham, Mastering Shiny

You should almost always use Shiny’s built-in mechanisms for setting and accessing variables. I highly recommend reading Mastering Shiny to be certain that you actually need this type of variable before using the options presented here.

Shiny variables can be roughly divided into three categories:

  • App-wide variables that apply to all users: Use normal R variables, options (getOption()), and/or environment variables (Sys.getenv()).
  • Variables that apply to a single user: Almost always use Shiny’s reactiveValues(), reactiveVal(), reactive(), the input system, and/or return values from modules.
  • Variables that apply to a single user, are shared across multiple modules, and can be updated in multiple places: Use this package. These should be places where, in a non-Shiny context, you would use Sys.setenv() to set a variable (for yourself) and Sys.getenv() to get it.

But if you’re sure you want to…

Instead of Sys.setenv(), use shinyenv::shiny_setenv(),

# NO: Sys.setenv(foo = "bar", baz = "foo")
shinyenv::shiny_setenv(foo = "bar", baz = "foo")

Instead of Sys.getenv(), use shinyenv::shiny_getenv(),

# NO: Sys.getenv("foo")
shinyenv::shiny_getenv("foo")

Code of Conduct

Please note that the shinyenv project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.