Trying a multi output shiny app with reproducibility by shinymeta
This repo contains two apps that try using the new shinymeta package. The apps basically
Filter
one data set (event_data
)Select
a second data set (pat_data
)- Merge the two data sets on keys
- Create a linear model from measurements in
event_data
vs selected columns inpat_data
- Plot the linear model
- Show the summary of the linear model
- Make it reproducible by a "Show R Code" button
get shinymeta from github by
devtools::install_github("rstudio/shinymeta")
The example shown here is a typical analysis in clinical studies. Though the data is totally randomized.
For the clinical study the biostatistician wants to see different plots for different events. He wants to take the one with the highest impact into the study report. This study report will be send to authorities like FDA. The FDA would like to see how the plot was produced and which data went in. The reproducibility feature would allow the FDA to create the plot themselves by having the app or the report + code.
app.R
contains an app that just uses metaReactive
s like shown in the example by
shinymeta
. I basically tried to put everything in. This app
though produces some ugly code
formula_reactive <- AVAL ~ AGE
I just wanted to see the outcome of this in my reproducible code. So e.g. AVAL ~ AGE
. Therefore I tried to use
a standard shiny::reactive
instead of a metaReactive
in the second app app_mixed_reactives.R
:
formula_reactive <- reactive({
validate(need(is.character(input$select_regressor), "Cannot work without selected column"))
regressors <- Reduce(function(x, y) call("+", x, y), rlang::syms(input$select_regressor))
rlang::new_formula(rlang::sym("AVAL"), regressors)
})
# Create a linear model
model_reactive <- metaReactive2({
validate(need(is.data.frame(data_set_reactive()), "Data Set could not be created"))
validate(need(is.language(formula_reactive()), "Formula could not be created from column selections"))
metaExpr({
model_data <- !!data_set_reactive()
lm(formula = !!formula_reactive(), data = model_data)
})
})
surprisingly it worked and the R Code looks nice