This function generates the Shiny app. It is the main function of the package. The app can either be launched directly, or saved to
a folder. If saved, that folder will contain all the code and data needed to run the app. The app can then be launched using shiny::shinyAppDir()
on that folder, or modified by editing server.R, ui.R, global.R and models.R in the folder.
Usage
generate_shiny(
dataset,
dataset_name,
eff_size_type_label = NA,
models = get_model_tibble,
primary_model = NULL,
filter_popups = list(),
save_to_folder = NA,
launch_app = is.na(save_to_folder) && is.null(static_folder),
...,
options = list(),
overwrite = FALSE,
bayesian = NULL,
design = NULL,
study_info = NULL,
static_folder = NULL
)Arguments
- dataset
Dataframe as returned from
prepare_data()- dataset_name
Name of the dataset
- eff_size_type_label
The label to be used to describe the effect size. If NA, uses
"Correlation r"for correlations,"Odds ratio"or"Risk ratio"for ratios, and otherwise the effect type code from the dataset.- models
The models to be included in the app. Can either be a function to call, a tibble, or the path to a file. Custom models can add an
interval_typecolumn naming their interval, such as "Confidence interval"; otherwise the app says that its type is unknown.LCL90andUCL90columns give the 90% interval used by the equivalence assessment; a model without them is not assessed there. Adescriptioncolumn gives a sentence that the app's Methods section shows for that model. If you want to change the default models, have a look at the vignette and/or theget_model_tibble()documentation. Passing a file (e.g. "my_models.R") is particularly helpful if you include helper functions and save the app. If so, this must assign the tibble to a variable called models_to_run (i.e. using <-).- primary_model
Optional name of the one model (a
nameinmodels) that the authors treat as their primary analysis. Generated apps show it first and label the other rows as explorations. If it cannot be estimated for a reader's selection, the app reports why and does not substitute another model. The default,NULL, declares no primary model, and the app then says that it does not choose between estimators.- filter_popups
Named list of expandable filter-help content. Plain text is escaped; wrap trusted HTML in
htmltools::HTML(), for examplelist(Year = htmltools::HTML("<i>Note:</i> Data collection year.")).- save_to_folder
Folder for the generated code and data. Defaults to NA, which uses a temporary folder. A nonempty destination is refused unless overwrite = TRUE. Prefer a fresh destination to preserve manual edits.
- launch_app
Should the app be launched? Defaults to TRUE if save_to_folder is NA and static_folder is NULL, FALSE otherwise. Interactive auto-printing of the returned app launches it and blocks the R console until the app stops. Use launch_app = FALSE to build without launching, then run shiny::runApp() separately when ready.
- ...
Arguments passed on to
create_aboutdateDate of the last update. Defaults to the current date.
citationCitation requested by the author. Defaults to an empty string. Inserted into About as HTML, so it can contain markup such as
<i>; write&and<for a literal&or<.osf_linkLink to the OSF (or similar) project where data and materials are available. Defaults to an empty string. Inserted into About as a link (HTML).
contactContact information, typically email. Defaults to an empty string. Inserted into About as HTML.
list_packagesShould all packages used by the app be listed on the About page? If TRUE, it lists the packages used in the default configuration. To display different packages (e.g., because you added/removed models), pass a character vector with all packages to display.
- options
List of more detailed options to customise your app. They all have sensible defaults and are thus rarely needed.
max_forest_plot_rowsNumeric. How many effects fit on one page of the forest plot's PDF download, which holds every selected study? Defaults to 60; a study with more effects gets a page of its own. The plot on screen shows 50 studies to a page, and its PNG download the page shown.shiny_themeCharacter. One of the shinythemes that style the app. Defaults to "yeti", see?shinythemes::shinythemesfor all options.introOptional HTML shown under the title: one or two sentences stating the question and, for readers new to the scale, what positive values mean.fit_cache_entriesInteger 0 to 3. Recent exact selections per reader session; 0 disables caching. Defaults to 3 for default models and 0 for custom code.selection_list_thresholdNumeric. From how many filter levels should a selection box be shown instead of check boxes? Defaults to 6.correlation_dependentNumeric, at least 0 and below 1. The assumed correlation between the sampling errors of effects from the same study, used to compute the sampling variance of study-level averages, in the multilevel (CHE) model and for the RVE weights. Defaults to .6.aggregation_methodCharacter. How multiple effects from the same study are combined for study-level models (bias analyses, the opt-in Bayesian model) and combined forest-plot rows:"unweighted"(default; unweighted study-level mean with correlated sampling variance, Borenstein et al., 2009, matchingmetafor::aggregate.escalc(..., weighted = FALSE)),"gls"(inverse-covariance GLS average, matchingmetafor::aggregate.escalc(..., weighted = TRUE); assumes zero within-study heterogeneity and warns when negative weights arise), or"first"(first selected effect per study).
- overwrite
Explicit opt-in to replace generated files in a nonempty destination. Unrelated files are retained.
- bayesian
NULL (default), or list(enabled = TRUE, tau_scale = .5). Adds a deterministic study-level normal-normal model with a flat prior on the mean and a half-normal heterogeneity prior, computed by grid quadrature over the heterogeneity (no extra package needed). Correlation default tau_scale is .25 on Fisher z. An optional
max_studies(integer, at least 2) caps the number of studies; by default there is no cap. Sensitivity analyses use half and double the scale. Cannot be combined with amodelsfile path; supply a tibble orget_model_tibbleinstead.- design
Optional settings from
app_design(). Usedesign_app()to preview and export them.- study_info
Optional study information shown to readers: a data frame (or CSV path) with one row per study and a
studycolumn matching the study IDs, as returned byfetch_study_metadata()or written by the authors. Recognised columns:doi,url,title,authors(separated by "; "),year,journal,volume,issue,pages,reference(the full reference as text),bibtex(a BibTeX entry),abstract(paragraphs separated by blank lines),abstract_licence(licence URL),abstract_note,metadata_source,retrieved, plusstatusandabstract_policyfrom the lookup. Studies in the effect-size list then open a details row, and readers can download the references for their selection. It is stored in the app; the app never fetches metadata. Include only abstracts you may republish.- static_folder
Optional destination folder for a static shinylive site. Requires the suggested shinylive package. The app is generated in save_to_folder first (a temporary folder when NA), then exported with precomputed results. Must be outside save_to_folder. Static generation never launches the app.
Value
With static_folder supplied, invisibly returns the static site path. Otherwise, with launch_app = FALSE, invisibly returns the generated app folder path. With launch_app = TRUE, returns a Shiny app object; printing it launches the app and blocks the console until it stops.
Details
Use generate_shiny(static_folder = ...) to generate and publish static files
in one step. After editing the generated app files, use export_static() to
re-export them; regenerating the app would overwrite those edits.
With overwrite = TRUE, the existing static site folder is deleted entirely
and rewritten, including unrelated files. Keep hand edits in the editable app
folder and re-export it with export_static().
Examples
raw <- data.frame(study = letters[1:6], d = c(.1, .3, -.1, .4, .2, .5),
vi = c(.02, .03, .02, .04, .01, .05))
app_data <- prepare_data(raw, "study", "d", variance = "vi")
folder <- tempfile("metaui-example-")
generate_shiny(app_data, dataset_name = "Example", save_to_folder = folder,
launch_app = FALSE)
#> Every study has one effect, so the default models use one random-effects model (metafor::rma.uni, REML, Hartung-Knapp interval) instead of the multilevel model and robust variance estimation. To keep those, pass models = get_model_tibble().
unlink(folder, recursive = TRUE)
