The switchboard package for R is an agile widget engine for creating dynamic, real-time dashboards for iterative simulations (e.g., for/while loops). It contains a growing, unsorted collection of visualization widgets rendered in a Tcl/Tk GUI–these include progress bars, counters, eavesdroppers, injectors, switches, and sliders. Below is a brief tutorial to get started on creating your own dashboards.
Updates to this vignette will be posted on our research webpage at USF.
For the source code of switchboard see: http://cran.r-project.org/web/packages/juicr/index.html or https://github.com/mjlajeunesse/switchboard.
Lajeunesse, M.J. (2021) Creating dynamic, real-time dashboards with the switchboard package for R. R package, v. 0.1.
Please email me any bugs, comments, or suggestions and I’ll try to include them in future releases: lajeunesse@usf.edu. Also try to include switchboard in the subject heading of your email. Finally, I’m open to almost anything, but expect a lag before I respond and/or new additions are added.
Here is how you would script a small Monte Carlo simulation exploring the effects of sample size on linear regression estimation:
library(switchboard)
library(MASS)
pop_rho <- 0
pop_X <- 0
pop_Y <- 0
pop_forget <- 400 #milliseconds
ctrl_regression <- FALSE
ctrl_N <- FALSE
for(i in 1:1e5) {
cov_XY <- matrix(c(1, pop_rho, pop_rho, 1), nrow = 2, ncol = 2)
sample_XY <- MASS::mvrnorm(1, mu = c(pop_X, pop_Y), Sigma = cov_XY)
switchboard() %>%
caption(c("Monte Carlo Simulation",
"Slide sample size to see how it impacts regression estimation.
Few samples results in poor estimation."),
placeOnGrid = c(1,1), size = 2) %>%
control_switch_pair(c("ctrl_regression", "ctrl_N"),
label = c("regression line", "plot N"), placeOnGrid = c(1,3)) %>%
control_slider_pair(c("pop_rho","pop_forget"),
minimum = c(-1, 4), maximum = c(1, 3000),
label = c("correlation", "sample size"),
placeOnGrid = c(2,3)) %>%
injector_2D(c(sample_XY[1], sample_XY[2]),
inject = c("pop_X", "pop_Y"),
minimum = c(-5,-5), maximum = c(5,5),
plotRegression = ctrl_regression, plotSampleSize = ctrl_N, size = 2,
forget = pop_forget, placeOnGrid = c(1,4), switch = TRUE)
}
switchboard_close()