### Install visOmopResults from GitHub Source: https://darwin-eu.github.io/visOmopResults/index.html Installs the development version of the visOmopResults package from GitHub using the pak package manager. ```r # install.packages("pak") pak::pkg_install("darwin-eu/visOmopResults") ``` -------------------------------- ### Install visOmopResults from CRAN Source: https://darwin-eu.github.io/visOmopResults/index.html Installs the latest stable version of the visOmopResults package from CRAN. ```r install.packages("visOmopResults") ``` -------------------------------- ### Example of Table Types (Related Function) Source: https://darwin-eu.github.io/visOmopResults/reference/plotType.html Demonstrates the output of a related function, tableType(), which lists supported table types. This is provided as an example of the type of output expected from similar utility functions. ```R tableType() #> [1] "gt" "flextable" "tibble" "datatable" "reactable" "tinytable" ``` -------------------------------- ### Load Packages and Mock Data for Shiny App Source: https://darwin-eu.github.io/visOmopResults/articles/a04_shiny_apps.html Loads all required R packages and mock data for building a Shiny application with visOmopResults. Ensure these packages are installed before running. ```r library(shiny) library(bslib) library(sortable) library(shinyWidgets) library(gt) library(DT) library(reactable) library(plotly) library(dplyr) library(visOmopResults) library(IncidencePrevalence) library(CohortCharacteristics) library(shinycssloaders) # Mock results in visOmopResults data <- visOmopResults::data # Remove global options (just in case we have them from previous work) setGlobalPlotOptions(style = NULL, type = NULL) setGlobalTableOptions(style = NULL, type = NULL) ``` -------------------------------- ### R Chunk for Package Loading and Setup Source: https://darwin-eu.github.io/visOmopResults/articles/a03_quarto_reports.html Load necessary R packages, load mock data, and set global options for knitr and visOmopResults plotting/table styles. This chunk prepares the environment for report generation. ```r # Load necessary packages ---- library(visOmopResults) library(IncidencePrevalence) library(CohortCharacteristics) library(dplyr) library(tidyr) library(ggplot2) # Load mock results stored in the package ---- data <- visOmopResults::data # Global options ---- knitr::opts_chunk$set( out.width = "95%", # figures occupy ~95% of document width out.height = "auto", dpi = 320, # ensure figure quality fig.width = 6, # default aspect ratio (can be overridden per-figure) fig.height = 3, results = "asis" # enable Markdown produced via cat() inside chunks ) # DARWIN style for visOmopResults plots and tables. style <- "darwin" tableType <- "flextable" plotType <- "ggplot" setGlobalPlotOptions(style = style, type = plotType) setGlobalTableOptions(style = style, type = tableType) ``` -------------------------------- ### Get Default Table Formatting Options Source: https://darwin-eu.github.io/visOmopResults/reference/tableOptions.html Retrieves a named list containing the default formatting options for visOmopTable() and visTable(). Use this to understand available customizations or to start with default settings. ```r tableOptions() ``` -------------------------------- ### Example Usage of formatHeader Source: https://darwin-eu.github.io/visOmopResults/reference/formatHeader.html Demonstrates how to use the formatHeader function to pivot a summarised result object and format headers, excluding the header name. ```R result <- mockSummarisedResult() result |> formatHeader( header = c( "Study cohorts", "group_level", "Study strata", "strata_name", "strata_level" ), includeHeaderName = FALSE ) ``` -------------------------------- ### Darwin Style .yml Configuration Source: https://darwin-eu.github.io/visOmopResults/articles/a05_style.html Example structure of a .yml file for the 'darwin' style, defining colors, typography, and specific settings for Shiny, visOmopResults plots, and tables. ```yaml color: palette: white: '#ffffff' darwin_blue: '#003399' foreground: black background: white primary: darwin_blue logo: path: https://www.ema.europa.eu/sites/default/files/styles/oe_bootstrap_theme_medium_no_crop/public/2024-07/DARWINEU_logo_LARGE.png?itok=NtwlLhSX typography: base: family: Calibri size: 11pt defaults: shiny: theme: preset: flatly visOmopResults: template: system.file("darwinReportRef.docx", package = "visOmopResults") plot: font_family: Calibri font_size: 11pt background_color: white header_color: darwin_blue header_text_color: white header_text_bold: yes grid_major_color: '#d9d9d9' axis_color: '#252525' border_color: '#595959' legend_position: right table: font_family: Calibri font_size: 9pt border_color: darwin_blue border_width: 0.5 text_line_space: 1 text_space_before: 0 text_space_after: 6 header: background_color: darwin_blue text_bold: yes align: center text_color: white border_color: white font_size: 9pt header_name: background_color: darwin_blue text_bold: yes align: center text_color: white border_color: white font_size: 9pt header_level: background_color: darwin_blue text_bold: yes align: center text_color: white border_color: white font_size: 9pt column_name: background_color: darwin_blue text_bold: yes align: center text_color: white border_color: white font_size: 9pt group_label: background_color: darwin_blue text_bold: yes text_color: white border_color: white font_size: 9pt title: text_bold: yes align: center font_size: 15pt subtitle: text_bold: yes align: center font_size: 12pt body: border_width: 0.5 border_color: darwin_blue ``` -------------------------------- ### Create a flextable with custom formatting Source: https://darwin-eu.github.io/visOmopResults/reference/formatTable.html This example demonstrates how to use formatTable to create a flextable. It includes custom styling for missing values, header formatting, and specific options for grouping and cell merging. The input is first processed by mockSummarisedResult and formatEstimateValue. ```r mockSummarisedResult() |> formatEstimateValue(decimals = c(integer = 0, numeric = 1)) |> formatHeader( header = c("Study strata", "strata_name", "strata_level"), includeHeaderName = FALSE ) |> formatTable( type = "flextable", style = "default", na = "--", title = "fxTable example", subtitle = NULL, caption = NULL, groupColumn = "group_level", groupAsColumn = TRUE, groupOrder = c("cohort1", "cohort2"), merge = "all_columns" ) ``` -------------------------------- ### Example using visOmopTable with a mock SummarisedResult Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html Demonstrates the use of visOmopTable with a mock SummarisedResult object. This function is specialized for SummarisedResult objects and internally uses splitAll(). It allows specifying settings columns and special header values like 'strata' or 'settings'. ```R result <- mockSummarisedResult() | filter(strata_name == "age_group &&& sex") ``` -------------------------------- ### Create Mock Summarised Result Source: https://darwin-eu.github.io/visOmopResults/reference/mockSummarisedResult.html Generates an object of the class populated with mock data. This is useful for examples and testing. ```r mockSummarisedResult() ``` -------------------------------- ### Create a scatter plot with lines and points Source: https://darwin-eu.github.io/visOmopResults/reference/scatterPlot.html This example demonstrates how to create a scatter plot with both lines and points, faceted by age group and sex. Ensure the 'result' object is prepared and relevant columns are specified for x, y, and faceting. ```r result <- mockSummarisedResult() | dplyr::filter(variable_name == "age") scatterPlot( result = result, x = "cohort_name", y = "mean", line = TRUE, point = TRUE, ribbon = FALSE, facet = age_group ~ sex) #> `geom_line()`: Each group consists of only one observation. #> ℹ Do you need to adjust the group aesthetic? #> `geom_line()`: Each group consists of only one observation. #> ℹ Do you need to adjust the group aesthetic? #> `geom_line()`: Each group consists of only one observation. #> ℹ Do you need to adjust the group aesthetic? #> `geom_line()`: Each group consists of only one observation. #> ℹ Do you need to adjust the group aesthetic? #> `geom_line()`: Each group consists of only one observation. #> ℹ Do you need to adjust the group aesthetic? #> `geom_line()`: Each group consists of only one observation. #> ℹ Do you need to adjust the group aesthetic? #> `geom_line()`: Each group consists of only one observation. #> ℹ Do you need to adjust the group aesthetic? #> `geom_line()`: Each group consists of only one observation. #> ℹ Do you need to adjust the group aesthetic? #> `geom_line()`: Each group consists of only one observation. #> ℹ Do you need to adjust the group aesthetic? ``` -------------------------------- ### Access Mock Results Data Source: https://darwin-eu.github.io/visOmopResults/reference/data.html This snippet shows how to access the mock results data. This data is a list intended for use in Quarto and Shiny vignette examples. ```r data ``` -------------------------------- ### Get Available Table Styles Source: https://darwin-eu.github.io/visOmopResults/reference/tableStyle.html Retrieves a character vector of all pre-defined style names available for tables. Use this to see which styles can be applied. ```r tableStyle() ``` -------------------------------- ### Generate a reactable with grouped columns for single-level headers Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html When using type 'reactable', which supports only single-level headers, group columns using 'groupColumn' to achieve a similar structure. This example groups by 'species' and 'sex' while displaying 'island' as the primary header. ```R visTable( result = x, estimateName = c( "Bill length - Bill depth (mm)" = " - ", "Flipper length (mm)" = "" ), header = c("island"), groupColumn = c("species", "sex"), type = "reactable", hide = c("year", "estimate_type") ) ``` -------------------------------- ### Get Supported Columns for Tables Source: https://darwin-eu.github.io/visOmopResults/reference/tableColumns.html Retrieves a character vector of column names that can be used as input for the table functions. Requires a `summarised_result` object. ```r result <- mockSummarisedResult() tableColumns(result) ``` -------------------------------- ### Style gt Tables with visOmopTable Source: https://darwin-eu.github.io/visOmopResults/articles/a05_style.html Use visOmopTable with type 'gt' to apply custom styles to table headers, column names, group labels, and body text. Ensure the 'gt' package is installed. ```r result |> visOmopTable( estimateName = c("Mean (SD)" = " ()"), groupColumn = "cohort_name", header = c("This is an overall header", "sex"), type = "gt", style = list( header = list( cell_text(weight = "bold"), cell_fill(color = "red") ), header_name = list( cell_text(weight = "bold"), cell_fill(color = "orange") ), header_level = list( cell_text(weight = "bold"), cell_fill(color = "yellow") ), column_name = list( cell_text(weight = "bold") ), group_label = list( cell_fill(color = "blue"), cell_text(color = "white", weight = "bold") ), title = list( cell_text(size = 20, weight = "bold") ), subtitle = list( cell_text(size = 15) ), body = list( cell_text(color = "red") ) ), .options = list( title = "My formatted table!", subtitle = "Created with the `visOmopResults` R package.", groupAsColumn = FALSE, groupOrder = c("cohort2", "cohort1") ) ) ``` -------------------------------- ### Prepare Data for visTable Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html Load necessary libraries and prepare a sample data frame using dplyr and tidyr for use with visTable(). ```R library(visOmopResults) library(palmerpenguins) library(dplyr) library(tidyr) x <- penguins | filter(!is.na(sex) & year == 2008) | select(!"body_mass_g") | summarise(across(ends_with("mm"), ~mean(.x)), .by = c("species", "island", "sex")) head(x) #> # A tibble: 6 × 6 #> species island sex bill_length_mm bill_depth_mm flipper_length_mm #> #> 1 Adelie Biscoe female 36.6 17.2 187. #> 2 Adelie Biscoe male 40.8 19.0 193. #> 3 Adelie Torgersen female 36.6 17.4 190 #> 4 Adelie Torgersen male 40.9 18.8 194. #> 5 Adelie Dream female 36.3 17.8 189 #> 6 Adelie Dream male 40.1 18.9 195 ``` -------------------------------- ### Get Supported Table Classes Source: https://darwin-eu.github.io/visOmopResults/reference/tableType.html Call tableType() to get a character vector of table classes that can be used with visOmopTable(), visTable(), and formatTable(). ```r tableType() ``` ```r tableType() #> [1] "gt" "flextable" "tibble" "datatable" "reactable" "tinytable" ``` -------------------------------- ### Get Supported Plot Types Source: https://darwin-eu.github.io/visOmopResults/reference/plotType.html Call plotType() to get a character vector of all supported plot types for use in plot functions. ```R plotType() ``` -------------------------------- ### Running a Shiny Application Source: https://darwin-eu.github.io/visOmopResults/articles/a04_shiny_apps.html This snippet shows the command to run a Shiny application by combining the UI and server components. Ensure the 'app.R' file contains both 'ui' and 'server' objects. ```R shinyApp(ui, server) ``` -------------------------------- ### Get Available Plot Styles Source: https://darwin-eu.github.io/visOmopResults/reference/plotStyle.html Call plotStyle() to retrieve a list of all available pre-defined plot styles. This function requires no arguments. ```r plotStyle() ``` -------------------------------- ### Load Required Libraries Source: https://darwin-eu.github.io/visOmopResults/articles/a05_style.html Loads essential R packages for data manipulation, visualization, and reporting with visOmopResults. ```r library(visOmopResults) library(here) library(gt) library(ggplot2) library(dplyr) library(officer) ``` -------------------------------- ### Explore Table Styling Options Source: https://darwin-eu.github.io/visOmopResults/articles/a04_shiny_apps.html Examine available styling functions for `datatable` and `reactable` outputs when using `visTable` for custom table generation. ```R tableStyle("datatable") tableStyle("reactable") ``` -------------------------------- ### Get Plot Columns Source: https://darwin-eu.github.io/visOmopResults/reference/plotColumns.html Retrieves a character vector of column names supported by the plot functions. Use this to understand which columns can be passed to plotting arguments. ```r result <- mockSummarisedResult() plotColumns(result) ``` -------------------------------- ### Generate Reactable OMOP Table Source: https://darwin-eu.github.io/visOmopResults/reference/visOmopTable.html This snippet shows how to generate an interactive table using the 'reactable' package with visOmopTable. It configures estimate names, headers, and column renames, similar to the default table, but leverages Reactable for enhanced interactivity. ```r result |> visOmopTable( estimateName = c( "N%" = " ()", "N" = "", "Mean (SD)" = " ()" ), header = c("cohort_name"), rename = c("Database name" = "cdm_name"), groupColumn = strataColumns(result), type = "reactable" ) ``` -------------------------------- ### Create Box Plot from Tibble Source: https://darwin-eu.github.io/visOmopResults/reference/boxPlot.html Generates a basic box plot from a tibble using the 'year' column for the x-axis. This example demonstrates the fundamental usage of the `boxPlot` function. ```r dplyr::tibble(year = "2000", q25 = 25, median = 50, q75 = 75, min = 0, max = 100) |> boxPlot(x = "year") ``` -------------------------------- ### Load visOmopResults and mock data Source: https://darwin-eu.github.io/visOmopResults/index.html Loads the visOmopResults package and generates a mock summarised_result object for demonstration purposes. ```r library(visOmopResults) result <- mockSummarisedResult() ``` -------------------------------- ### Apache License 2.0 Boilerplate Source: https://darwin-eu.github.io/visOmopResults/LICENSE.html Use this boilerplate notice to apply the Apache License to your work. Replace bracketed information with your specific details. ```text Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` -------------------------------- ### Generate a gt table with custom estimates and headers Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html Use visTable with type 'gt' to create a static table. Customize displayed estimates using 'estimateName' and specify visible columns with 'header'. Columns can be hidden using 'hide'. ```R visTable( result = x, estimateName = c( "Bill length - Bill depth (mm)" = " - ", "Flipper length (mm)" = "" ), header = c("species", "island"), groupColumn = "sex", type = "gt", hide = c("year", "estimate_type") ) ``` -------------------------------- ### Creating an interactive plotly box plot Source: https://darwin-eu.github.io/visOmopResults/articles/a02_plots.html Generates an interactive box plot of penguin body mass using plotly. Filters data similarly to the static plot example and applies custom labels and y-axis limits. ```r penguinsSummary | filter( group_level != "overall", strata_name == "year &&& sex", !grepl("NA", strata_level), variable_name == "body_mass_g") | boxPlot(x = "species", facet = cdm_name ~ sex, colour = "year", type = "plotly") + ylim(c(0, 6500)) + labs(x = "My custom x label") ``` -------------------------------- ### Create an empty flextable Source: https://darwin-eu.github.io/visOmopResults/reference/emptyTable.html This snippet demonstrates how to create an empty table specifically formatted as a 'flextable'. The function supports various output types, and 'flextable' is one of them. ```r emptyTable(type = "flextable") ``` -------------------------------- ### Generate a flextable with custom estimates and headers Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html Use visTable with type 'flextable' to generate a flextable output. Similar to 'gt', it allows customization of estimates, headers, and hidden columns. ```R visTable( result = x, estimateName = c( "Bill length - Bill depth (mm)" = " - ", "Flipper length (mm)" = "" ), header = c("species", "island"), groupColumn = "sex", type = "flextable", hide = c("year", "estimate_type") ) ``` -------------------------------- ### List Available Table Styles Source: https://darwin-eu.github.io/visOmopResults/articles/a05_style.html Displays the names of all available table styling themes in the visOmopResults package. Use this to check which styles can be applied. ```r tableStyle() #> [1] "darwin" "default" ``` -------------------------------- ### Inspect Default Table Options Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html Retrieves and displays the default formatting options for tables, including settings for decimals, separators, and header inclusion. Use this to understand available customization parameters. ```r tableOptions() #> $decimals #> integer percentage numeric proportion #> 0 2 2 2 #> #> $decimalMark #> [1] "." #> #> $bigMark #> [1] "," #> #> $keepNotFormatted #> [1] TRUE #> #> $useFormatOrder #> [1] TRUE #> #> $delim #> [1] "\n" #> #> $includeHeaderName #> [1] TRUE #> #> $includeHeaderKey #> [1] TRUE #> #> $na #> [1] "–" #> #> $title #> NULL #> #> $subtitle #> NULL #> #> $caption #> NULL #> #> $groupAsColumn #> [1] FALSE #> #> $groupOrder #> NULL #> #> $merge #> [1] "all_columns" ``` -------------------------------- ### Create a Flextable with Custom Estimate Formats Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html Generates a flextable visualization of OMOP CDM results with specified estimate names and formats. Useful for displaying summarized data with different numerical representations. ```r visOmopTable( result = result, estimateName = c( "N (%)" = " (%)", "N" = "", "Mean (SD)" = " ()" ), header = c("package_name", "age_group"), groupColumn = c("cohort_name", "sex"), settingsColumn = "package_name", type = "flextable" ) ``` -------------------------------- ### Format and Display Summarized Results with visTable Source: https://darwin-eu.github.io/visOmopResults/reference/visTable.html This snippet demonstrates how to use the visTable function to format and display summarized results. It shows how to customize estimate names, headers, rename columns, define grouping columns, and hide specific columns. ```r result <- mockSummarisedResult() result |> visTable( estimateName = c("N%" = " ()", "N" = "", "Mean (SD)" = " ()"), header = c("Estimate"), rename = c("Database name" = "cdm_name"), groupColumn = c("strata_name", "strata_level"), hide = c("additional_name", "additional_level", "estimate_type", "result_type") ) ``` -------------------------------- ### Generate Default OMOP Table Source: https://darwin-eu.github.io/visOmopResults/reference/visOmopTable.html This snippet demonstrates how to use visOmopTable to generate a default HTML table from summarised results. It customises estimate names, headers, and renames columns for better readability. The groupColumn argument is used to stratify the results. ```r result <- mockSummarisedResult() result |> visOmopTable( estimateName = c("N%" = " ()", "N" = "", "Mean (SD)" = " ()"), header = c("cohort_name"), rename = c("Database name" = "cdm_name"), groupColumn = strataColumns(result) ) ``` -------------------------------- ### Generate an interactive datatable with custom estimates and headers Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html Use visTable with type 'datatable' to create an interactive table. This format supports features like searching and pagination. Customize estimates, headers, and hidden columns as needed. ```R visTable( result = x, estimateName = c( "Bill length - Bill depth (mm)" = " - ", "Flipper length (mm)" = "" ), header = c("species", "island"), groupColumn = "sex", type = "datatable", hide = c("year", "estimate_type") ) ``` -------------------------------- ### Configure Global Table Options and Generate OMOP Table Source: https://darwin-eu.github.io/visOmopResults/reference/setGlobalTableOptions.html Sets global table styling to 'darwin' and type to 'tinytable' before generating a summarised OMOP table. This snippet shows how to map estimate names, define headers, rename columns, and specify grouping columns for the table. ```r setGlobalTableOptions(style = "darwin", type = "tinytable") result <- mockSummarisedResult() result | visOmopTable( estimateName = c("N%" = " ()", "N" = "", "Mean (SD)" = " ()"), header = c("cohort_name"), rename = c("Database name" = "cdm_name"), groupColumn = strataColumns(result) ) ``` -------------------------------- ### Set Global Table Options in R Source: https://darwin-eu.github.io/visOmopResults/reference/setGlobalTableOptions.html Configure default table styles and types for the entire session or project. Use pre-defined styles, YAML files, or custom R code for styling. Defaults to 'gt' table type if not specified. ```r setGlobalTableOptions(style = NULL, type = NULL) ``` -------------------------------- ### Create a gt Table with visTable Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html Use visTable() to generate a gt table from a data frame, specifying grouping, column renaming, and hiding columns. ```R visTable( result = x, groupColumn = c("sex"), rename = c( "Bill length (mm)" = "bill_length_mm", "Bill depth (mm)" = "bill_depth_mm", "Flipper length (mm)" = "flipper_length_mm" ), type = "gt", hide = "year" ) ``` -------------------------------- ### Create Header for GT and Flextable Objects Source: https://darwin-eu.github.io/visOmopResults/reference/index.html Use `formatHeader()` to create a header for gt and flextable objects. This function aids in table customization. ```R formatHeader() ``` -------------------------------- ### Generate Formatted Table from Data Table Source: https://darwin-eu.github.io/visOmopResults/reference/index.html Use `visTable()` to create a formatted table directly from a `` object. This is another main function for table generation. ```R visTable() ``` -------------------------------- ### Load visOmopResults Package Source: https://darwin-eu.github.io/visOmopResults/articles/a02_plots.html Loads the visOmopResults package for use in the current R session. This is a prerequisite for all other plotting functionalities. ```r library(visOmopresults) ``` -------------------------------- ### List Available Plot Styles Source: https://darwin-eu.github.io/visOmopResults/articles/a05_style.html Displays the names of all available plot styling themes in the visOmopResults package. Use this to check which styles can be applied. ```r plotStyle() #> [1] "darwin" "default" ``` -------------------------------- ### Create a Styled Alluvial Plot with Faceting Source: https://darwin-eu.github.io/visOmopResults/articles/a02_plots.html Generates a styled alluvial plot ('darwin' theme) showing penguin transitions across species, island, and sex, faceted by year, and colored by species. Requires data preparation including adding a 'year' column. ```r penguins |> filter(!is.na(sex)) |> mutate(year = as.character(year)) |> count(species, island, sex, year, name = "count") |> alluvialPlot( x = c("species", "island", "sex"), y = "count", colour = "species", facet = "year", style = "darwin" ) ``` -------------------------------- ### Format Estimate Name and Value Source: https://darwin-eu.github.io/visOmopResults/reference/formatEstimateName.html Demonstrates how to format estimate names and values using the formatEstimateName function. It shows how to specify new names and control whether unformatted rows are kept. ```r result <- mockSummarisedResult() result | formatEstimateName( estimateName = c( "N (%)" = " (%)", "N" = "" ), keepNotFormatted = FALSE ) ``` -------------------------------- ### Creating a Styled Table for Measurement Change Source: https://darwin-eu.github.io/visOmopResults/articles/a03_quarto_reports.html Transforms measurement change data into a format suitable for visTable, pivoting longer to create estimate columns and applying custom text formatting. Use this to generate styled tables for arbitrary data. ```r data$measurement_change |> tidyr::pivot_longer( cols = c("median", "min", "max", "q25", "q75"), names_to = "estimate_name", values_to = "estimate_value" ) | dplyr::mutate( estimate_type = "numeric", estimate_value = as.character(estimate_value), variable_name = customiseText(variable_name), sex = customiseText(sex) ) | visTable( header = "sex", estimateName = c( "Median [Q25 - Q75]" = " [ - ]", "Range" = " to " ), hide = c("cohort_name", "estimate_type"), rename = c("Estimate" = "estimate_name", "Variable" = "variable_name") ) ``` -------------------------------- ### Format Multi-Level Headers Source: https://darwin-eu.github.io/visOmopResults/articles/a01_tables.html Creates multi-level column headers using custom labels, column names, and column values. It allows for custom delimiters and controls the inclusion of header names and keys for styling purposes. ```r result <- result | mutate(across(c("strata_name", "strata_level"), ~ gsub("&&&", "and", .x))) |> formatHeader( header = c("Stratifications", "strata_name", "strata_level"), delim = "\n", includeHeaderName = FALSE, includeHeaderKey = TRUE ) ``` -------------------------------- ### Create Customised Characterisation Table Source: https://darwin-eu.github.io/visOmopResults/articles/a03_quarto_reports.html Generate a customised table of characteristics by modifying variable names and levels using `customiseText`. This allows for specific text replacements before rendering the table with `visOmopTable`. ```r data$summarised_characteristics |> dplyr::filter(variable_name != "Sex") | dplyr::mutate( variable_name = customiseText( variable_name, custom = c( "Comorbidities" = "Comorbidities flag -inf to 0", "Comedications" = "Comedications flag -180 to 0" ) ), variable_level = customiseText( variable_level, custom = c("HIV" = "Hiv") ) ) |> visOmopTable( header = c("sex"), estimateName = c( "N (%)" = " (%)", "N" = "", "Median [Q25 - Q75]" = " [ - ]", "Mean (SD)" = " ()", "Range" = " to " ), factor = list( "sex" = c("overall", "Male", "Female"), "variable_name" = c( "Number records", "Number subjects", "Age", "Days in cohort", "Prior observation", "Future observation", "Cohort start date", "Cohort end date", "Comedications", "Comorbidities" ), "variable_level" = c(NA, "Asthma", "Depression", "HIV", "Opioids", "Antidiabetes") ), hide = c("cdm_name", "cohort_name") ) ``` -------------------------------- ### Generate Formatted Table from Summarised Result Source: https://darwin-eu.github.io/visOmopResults/reference/index.html Use `visOmopTable()` to create a formatted table from a `` object. This function is part of the main table generation functions. ```R visOmopTable() ``` -------------------------------- ### Set Global Table Formatting Options Source: https://darwin-eu.github.io/visOmopResults/reference/index.html Use `setGlobalTableOptions()` to set format options that will apply to all subsequent tables generated by the package. ```R setGlobalTableOptions() ``` -------------------------------- ### Shiny Server Logic for Data Visualization Source: https://darwin-eu.github.io/visOmopResults/articles/a04_shiny_apps.html This snippet defines the server logic for a Shiny app, handling rendering of tables (gt, datatable, reactable) and plots (ggplotly, renderPlot) based on user inputs. It utilizes libraries like gt, visOmopResults, and plotly. ```R server <- function(input, output, session) { # Baseline (GT) output$summarise_characteristics_table <- gt::render_gt({ data$summarised_characteristics | # filter results by sex filterStrata(sex %in% input$summarise_characteristics_sex) | # create GT table CohortCharacteristics::tableCharacteristics( header = input$summarise_characteristics_table_header, groupColumn = input$summarise_characteristics_table_group_column, hide = input$summarise_characteristics_table_hide, type = "gt" ) }) # Large scale characteristics getLargeScaleResults <- reactive({ data$large_scale_characteristics | filter(.data$sex %in% input$large_scale_sex) }) # To render as DT output$large_dt <- renderDT({ getLargeScaleResults() | visTable( hide = input$large_scale_hide, groupColumn = input$large_scale_group_column, type = "datatable", style = list( filter = "top", searchHighlight = TRUE, rownames = FALSE ) ) }) # To render as reactable output$large_reactable <- reactable::renderReactable ({ getLargeScaleResults() | visTable( hide = input$large_scale_hide, groupColumn = input$large_scale_group_column, type = "reactable", style = "default" ) }) # Incidence getIncidencePlot <- reactive({ data$incidence | filterStrata(sex %in% input$incidence_sex) | plotIncidence( colour = input$colour, facet = input$facet, ribbon = input$inc_ribbon ) + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) }) output$incidence_plot <- renderUI({ plt <- getIncidencePlot() if (input$interactive) { ggplotly(plt) } else { renderPlot(plt) } }) } ``` -------------------------------- ### Generate an Empty Table Source: https://darwin-eu.github.io/visOmopResults/reference/index.html The `emptyTable()` function returns an empty table object, useful for placeholder or initial states. ```R emptyTable() ``` -------------------------------- ### Create a Basic Scatter Plot Source: https://darwin-eu.github.io/visOmopResults/articles/a02_plots.html Generates a scatter plot showing the median bill depth over years, with lines and points, faceted by CDM name and colored by species. Requires the penguinsSummary dataset. ```r penguinsSummary |> filter(variable_name == "bill_depth_mm") | filterStrata(year != "overall", sex == "overall") | scatterPlot( x = "year", y = "median", line = TRUE, point = TRUE, ribbon = FALSE, facet = "cdm_name", colour = "species" ) ``` -------------------------------- ### Shiny App Navigation Bar Layout Source: https://darwin-eu.github.io/visOmopResults/articles/a04_shiny_apps.html Defines the main navigation structure for a Shiny app using bslib's page_navbar. Includes panels for 'Baseline Characteristics' and 'Large Scale Characterisation'. ```R ui <- bslib::page_navbar( title = "visOmopResults for Shiny", window_title = "visOmopResults • Shiny", collapsible = TRUE, # Baseline Characteristics (GT table) bslib::nav_panel( title = "Baseline Characteristics", icon = icon("users-gear"), bslib::layout_sidebar( sidebar = bslib::sidebar( title = "Filters", shinyWidgets::pickerInput( inputId = "summarise_characteristics_sex", label = "Sex", choices = c("overall", "Male", "Female"), selected = "overall", multiple = TRUE ), width = 320, position = "left", open = TRUE ), bslib::card( full_screen = TRUE, bslib::card_header("Table layout"), bslib::layout_sidebar( sidebar = bslib::sidebar( title = "Arrange columns", sortable::bucket_list( header = NULL, group_name = "col-buckets", orientation = "horizontal", add_rank_list( text = "None", labels = c("variable_name", "variable_level", "estimate_name"), input_id = "summarise_characteristics_table_none" ), add_rank_list( text = "Header", labels = c("sex"), input_id = "summarise_characteristics_table_header" ), add_rank_list( text = "Group columns", labels = c("cdm_name", "cohort_name"), input_id = "summarise_characteristics_table_group_column" ), add_rank_list( text = "Hide", labels = "table_name", input_id = "summarise_characteristics_table_hide" ) ), position = "right", width = 400, open = FALSE ), # GT output gt::gt_output("summarise_characteristics_table") | shinycssloaders::withSpinner(type = 4) ) ) ) ), # Large Scale Characterisation (DT / reactable) bslib::nav_panel( title = "Large Scale Characterisation", icon = icon("table"), bslib::layout_sidebar( sidebar = bslib::sidebar( # title = "Display options", shinyWidgets::pickerInput( inputId = "large_scale_sex", label = "Sex", choices = c("overall", "Male", "Female"), selected = "overall", multiple = TRUE ), radioButtons( "large_engine", "Renderer", choices = c("DT", "reactable"), inline = TRUE ), sortable::bucket_list( header = NULL, group_name = "col-buckets", orientation = "horizontal", add_rank_list( text = "None", labels = c("variable_name", "variable_level", "estimate_name"), input_id = "large_scale_none" ), add_rank_list( text = "Group columns", labels = c("cdm_name", "cohort_name"), input_id = "large_scale_group_column" ), add_rank_list( text = "Hide", labels = character(), input_id = "large_scale_hide" ) ), width = 320 ), bslib::card( full_screen = TRUE, bslib::card_header("Cohort characteristics (large-scale)"), conditionalPanel( "input.large_engine == 'DT'", DTOutput("large_dt") |> shinycssloaders::withSpinner(type = 4) ), conditionalPanel( "input.large_engine == 'reactable'", reactableOutput("large_reactable") |> shinycssloaders::withSpinner(type = 4) ) ) ) ), # Incidence (ggplot → plotly) bslib::nav_panel( title = "Incidence", icon = icon("chart-line"), bslib::layout_sidebar( sidebar = bslib::sidebar( title = "Plot options", shinyWidgets::pickerInput( "incidence_sex", "Sex strata", choices = c("overall", "Male", "Female"), selected = "overall", multiple = TRUE ), shinyWidgets::pickerInput( inputId = "facet", label = "Facet", selected = "sex", multiple = TRUE, choices = c("cdm_name", "incidence_start_date", "sex", "outcome_cohort_name"), ), shinyWidgets::pickerInput( inputId = "colour", label = "Colour", selected = "outcome_cohort_name", multiple = TRUE, choices = c("cdm_name", "incidence_start_date", "sex", "outcome_cohort_name") ), checkboxInput("inc_ribbon", "Show ribbon (CI)", TRUE), checkboxInput("interactive", "Interactive Plot", TRUE), width = 320 ), bslib::card( full_screen = TRUE, bslib::card_header("Incidence over time") ) ) ) ) ``` -------------------------------- ### Create a Basic Box Plot Source: https://darwin-eu.github.io/visOmopResults/articles/a02_plots.html Generates a box plot of body mass by year, faceted by species and CDM name, and colored by sex, using the default style. Requires filtering for body mass variable. ```r penguinsSummary |> filter(variable_name == "body_mass_g") | boxPlot(x = "year", facet = species ~ cdm_name, colour = "sex", style = "default") ``` -------------------------------- ### Create a Styled Scatter Plot with Density Source: https://darwin-eu.github.io/visOmopResults/articles/a02_plots.html Generates a scatter plot of density values, with lines but no points, faceted by CDM name and variable name, colored by species, and styled with the 'darwin' theme. Requires filtering for specific variables and strata. ```r penguinsSummary |> filter(variable_name %in% c("bill_length_mm", "bill_depth_mm")) |> filterStrata(year == "overall", sex == "overall") | filterGroup(species != "overall") | scatterPlot( x = "density_x", y = "density_y", line = TRUE, point = FALSE, ribbon = FALSE, facet = cdm_name ~ variable_name, colour = "species", style = "darwin" ) ``` -------------------------------- ### Displaying Mock Measurement Change Data Source: https://darwin-eu.github.io/visOmopResults/articles/a03_quarto_reports.html This snippet displays the structure of mock measurement change data, showing cohort, sex, variable, and estimated values (median, min, max, quartiles). ```r data$measurement_change #> # A tibble: 9 × 8 #> cohort_name sex variable_name median min max q25 q75 #> #> 1 denominator overall value_before 60 24 117 55 77.2 #> 2 denominator overall value_after 58 22 108 55 72 #> 3 denominator overall change_in_value -2 -2 -9 0 -5.25 #> 4 denominator male value_before 65 30 120 61 80 #> 5 denominator male value_after 66 33 117 62 79 #> 6 denominator male change_in_value 1 3 -3 1 -1 #> 7 denominator female value_before 53 20 100 48 59 #> 8 denominator female value_after 50 19 100 47 60 #> 9 denominator female change_in_value -3 -1 0 -1 1 ```