The aim of the package demoShiny is to mimic the demo functionality for Shiny apps for a package.

Which Shiny apps are available?

With demoShiny you can get an overview about all apps from the loaded packages:

library("demoShiny")
#> Loading required package: shiny
demoShiny()
#>   topic                 
#> 2 demoShiny::correlation
#> 3 demoShiny::dbscan     
#> 1 demoShiny::hist       
#> 5 demoShiny::scagnostics
#> 6 demoShiny::silhouette 
#>   file                                                        
#> 2 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/correlation
#> 3 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/dbscan     
#> 1 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/hist.R     
#> 5 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/scagnostics
#> 6 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/silhouette

The output is a data frame with package::topic and the file or directory which would be called by demoShiny.

You can question for specific apps:

demoShiny('demoShiny')
#>   topic                 
#> 2 demoShiny::correlation
#> 3 demoShiny::dbscan     
#> 1 demoShiny::hist       
#> 5 demoShiny::scagnostics
#> 6 demoShiny::silhouette 
#>   file                                                        
#> 2 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/correlation
#> 3 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/dbscan     
#> 1 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/hist.R     
#> 5 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/scagnostics
#> 6 /tmp/RtmpqtjVUy/Rinst2fda2440ebc/demoShiny/shiny/silhouette

It will deliver all demo apps of the package demoShiny AND all apps named demoShiny!

How to run a single example app?

In case that for your topic is just one app available then no list will be returned but the Shiny demo app will be started:

# full topic
demoShiny('demoShiny::hist')
# if only one app is available then it will be run
demoShiny('hist')
# abbreviation for topics or packages can used
demoShiny('d::hist')

App installation for a package in inst/shiny

If you develop a package then create under inst a directory shiny. Each subdirectory of shiny can contain one app. The name of the subdirectory is the topic name.

list.files(system.file('shiny', package="demoShiny"), include.dirs=TRUE)
#> [1] "correlation" "dbscan"      "hist"        "hist.R"      "scagnostics"
#> [6] "silhouette"

As you can see the shiny subdirectory of demoShiny contains several directories, e.g. app1, silhouette, and also a file app1.R.

If you put an R file with the same name as a directory then the R file is sourced instead of calling the app in the directory. The aim is to allow for a specific calls to the app, e.g. by setting URL parameters:

launch.browser <- function(url) {
  # modify URL, which has no effect for app1 :(
  url <- sprintf('%s/?lang=%s', url, 'de')
  invisible(.Call("rs_shinyviewer", url, getwd(), 3))
}
#
library("shiny")
runApp(system.file('shiny', 'hist', package='demoShiny'), launch.browser=launch.browser)