Revolutionizing Clinical Research with Interactive Reports: Shiny and Quarto in Action

Estimated time:
time
min

The introduction of innovative tools like <a href="https://appsilon.com/r-shiny-pharma-open-source/" target="_blank" rel="noopener"><strong>Shiny</strong></a> and <strong>Quarto</strong> has empowered researchers and data scientists to transform complex data into interactive and insightful reports. This progress is not just an improvement in data visualization but a significant leap towards a new paradigm in clinical research. In this article, we'll delve into the <strong>core functionalities </strong>of<strong> Shiny</strong> and <strong><a href="https://appsilon.com/interactive-quarto-report-translation-tutorial/" target="_blank" rel="noopener">Quarto</a></strong> and explore how we can create dynamic and interactive reports with practical examples. <h3>Table of Contents</h3> <ul><li><a href="#getting-started">Getting Started with Shiny and Quarto</a></li><li><a href="#clinical-research">Shiny and Quarto in Clinical Research</a></li><li><a href="#application">A Shiny Application in Quarto</a></li><li><a href="#conclusion">Conclusion</a></li><li><a href="#resources">Resources</a></li><li><a href="#connect">Connect with Us</a></li></ul> <h2 id="getting-started">Getting Started with Shiny and Quarto</h2> <h3>Brief Introduction to Shiny and Quarto</h3> Before we dive into the practical aspects of using Shiny and Quarto in clinical research, let's get a brief understanding of these powerful tools: <h4>Shiny</h4> <a href="https://shiny.posit.co/" target="_blank" rel="noopener noreferrer">Shiny</a> is an R package that empowers you to create interactive web applications with ease. It's particularly <strong>well-suited for building interactive reports and dashboards</strong>, making it an excellent choice for <strong>presenting clinical research data</strong> in an <strong>engaging</strong> and <strong>user-friendly</strong> manner. With Shiny, you can <strong>seamlessly integrate R code</strong> with web-based user interfaces, allowing you to create interactive elements like sliders, buttons and plots that respond to user inputs in real time. <h4>Quarto</h4> <a href="https://quarto.org/" target="_blank" rel="noopener noreferrer">Quarto</a> is a dynamic document format that combines code, text and graphics into a single, cohesive document. It's designed to make <strong>reproducible reporting</strong> and <strong>sharing of research findings straightforward</strong>. Quarto integrates with R and other programming languages, making it a valuable tool for creating dynamic clinical research reports that can be easily updated as new data becomes available. <img class="size-full wp-image-22051" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b0197058ad7af22dfd91bb_Untitled-4.webp" alt="An example of a Quarto document demonstrating the use of shiny.i18n for interactive translation, featuring a quote by Steve Jobs." width="600" height="440" /> <a href="https://appsilon.com/interactive-quarto-report-translation-tutorial/" target="_blank" rel="noopener">Interactive Quarto Reports with Shiny</a> <h3>Installation and setup instructions</h3> To get started with Shiny and Quarto, you'll need to set up your environment. Here's a step-by-step guide to help you install and configure these tools: <h4>Install R and RStudio</h4><ul><li>If you haven't already, download and install R from <a href="https://cran.r-project.org/bin/windows/base/" target="_blank" rel="noopener noreferrer">CRAN</a>.</li><li>Install RStudio, an integrated development environment for R, from the <a href="https://posit.co/download/rstudio-desktop/" target="_blank" rel="noopener noreferrer">RStudio website</a>.</li></ul> <h4>Install Shiny</h4><ul><li>Open RStudio.</li><li>In the RStudio console, run the following command to install the Shiny package:</li></ul> <pre><code> install.packages("shiny") </code></pre> <h4>Install Quarto</h4><ul><li>Go to <a href="https://quarto.org/docs/get-started/" target="_blank" rel="noopener noreferrer">Quarto Get Started Page.</a></li><li>Download the Quarto CLI setup file according to your OS. Open the downloaded setup file to install Quarto CLI.</li><li>Install dependencies<ul><li>Non-RStudio installation: Select your preferred IDE on the same page to see instructions.</li><li>RStudio installation: Follow the instructions below or select RStudio on the same page and see the latest instructions from Posit.</li></ul> </li> <li>In the RStudio console, run the following commands to install dependencies:</li> </ul> <pre><code> install.packages("tidyverse") install.packages("palmerpenguins") </code></pre> <ul><li>Download a Quarto file.</li><li>Open the file in RStudio and click on Render button.</li></ul> <h4>Create a New Shiny App</h4><ul><li>To create a new Shiny app, go to File &gt; New File &gt; Shiny Web App in RStudio.</li><li>Follow the prompts to set up your Shiny app, including choosing a directory and a name for your app.</li></ul> <h4>Start a new Quarto Document</h4><ul><li>To start a new Quarto document, you can create a plain text file with the ".quarto" extension.</li><li>You can also use the "New File" option in RStudio and select "Quarto Document" to create a Quarto document.</li><li>In the dialogue box, you have the option to output a Document, Presentation or Interactive webpage.</li></ul> <img class=" wp-image-22059" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b019715fde21bea0ae487d_Untitled-5.webp" alt="A screenshot of a dialog window for creating a new Quarto document, showing options for document type, title, author, output formats (HTML, PDF, Word), and settings for the engine and editor." width="590" height="526" /> New Quarto Document Creation Interface <ul><li>For each of the sections, there are some additional inputs needed.</li><li>Title and author are the 1st 2 inputs. Followed by the final output format. You could select the one you need and leave the engine settings to its default value.</li><li>Finally, click on Create to create the new Quarto file.</li></ul> <h4>Install Required Packages</h4><ul><li>Depending on your specific needs, you may need to install additional R packages for data analysis, visualization, or other tasks.</li><li>You can install packages using the install.packages() function.</li></ul> Now that you have Shiny and Quarto set up, you can begin creating interactive clinical research reports and dashboards. In the following sections, we'll delve deeper into how to harness the power of Shiny and Quarto to transform your clinical research projects. Next, let's explore practical examples and case studies that demonstrate their capabilities. <blockquote>Wondering how open-source technology is transforming pharmaceutical data analysis? Check out this article for an in-depth look at <a href="https://appsilon.com/r-shiny-pharma-open-source/" target="_blank" rel="noopener">how R Shiny is leading the way in creating more efficient and transparent research methodologies</a>.</blockquote> <h2 id="clinical-research">Shiny and Quarto in Clinical Research</h2> <h3>Clinical Trial Analysis</h3> In this case study, we'll explore how Shiny and Quarto can be <strong>employed in a clinical trial setting to</strong> <strong>enhance data analysis</strong>, <strong>visualization</strong> <strong>and</strong> <strong>reporting</strong>. Clinical trials are pivotal in evaluating the safety and efficacy of new medical treatments, making them an ideal scenario for demonstrating the capabilities of these tools. Imagine you're conducting a clinical trial to assess the effectiveness of a new drug for treating a specific medical condition. Traditional reporting methods might involve static charts and tables that are time-consuming to update as new trial data emerges. However, with Shiny and Quarto, you can create an <a href="https://appsilon.com/how-i-built-an-interactive-shiny-dashboard-in-2-days-without-any-experience-in-r/" target="_blank" rel="noopener">interactive dashboard</a> that <strong>allows real-time exploration of trial outcomes</strong>, ensuring that medical professionals and researchers always have access to the latest information. <h3 id="application">A Shiny Application in Quarto</h3> Let's create a Quarto Shiny web application for analyzing clinical trial data using the <code>echarts4r</code> and <code>reactable</code> packages. This is a Shiny web application that analyzes clinical trial data using the <code>echarts4r</code> and <code>reactable</code> packages within the Shiny framework. It creates an interactive dashboard for exploring and visualizing clinical data. Let's break down the Quarto code step by step: <h4>YAML Header</h4> <pre><code> title: "Clinical Data Analysis with {echarts4r} and {reactable} in a Shiny App" format:  html:    page-layout: custom server: shiny </code></pre> This specifies metadata and configuration for the document. <ul><li>The title is set to "Clinical Data Analysis with {echarts4r} and {reactable} in a Shiny App."</li><li>The document format is specified as an HTML page with a custom layout.</li><li>The server is set to "shiny," indicating that this document will be used for a Shiny web application.</li></ul> <h4>R Setup Chunk</h4> <pre><code class="language-r"> # Load your clinical trial data remotes::install_github(  "insightsengineering/random.cdisc.data" ) data(  "cadsl", package = "random.cdisc.data" ) <br># Load the required libraries library(shiny) library(echarts4r) library(reactable) library(rmarkdown) library(dplyr) </code></pre> This code chunk loads the necessary data and libraries. <ul><li>We are installing a package to use sample data from the package <code>{random.cdisc.data}</code></li><li>The data is loaded to R memory</li><li>Libraries like <code>{shiny}</code>, <code>{echarts4r}</code>, <code>{reactable}</code>, <code>{rmarkdown}</code> and <code>{dplyr}</code> are loaded to provide the required functionality.</li></ul> <h4>Shiny User Interface (UI)</h4> <pre><code class="language-r"> #| panel: sidebar selectInput(  "sex_filter", "Select Sex", choices = c(    "All", unique(as.character(cadsl$SEX))  ) ) selectInput(  "race_filter", "Select Race", choices = c(    "All", unique(as.character(cadsl$RACE))  ) ) </code></pre> <ul><li>This section defines the user interface elements of the Shiny app.</li><li>It includes two <code>selectInput</code> elements within the sidebar panel, allowing users to select a sex and a race for data filtering.</li></ul> <h4>UI Panel for Data Visualization</h4> <pre><code class="language-r"> #| panel: fill echarts4rOutput("echarts_plot") h4("Data used for plot") reactableOutput("reactable_table") </code></pre> <ul><li>This section defines the panels for displaying data visualizations.</li><li>It includes an echarts4r plot output <code>(echarts_plot)</code> and a reactable table output <code>(reactable_table)</code> within the main content area.</li></ul> <h4>Shiny Server Logic</h4> <pre><code class="language-r"> #| context: server filtered_data &lt;- reactive({    df &lt;- cadsl    if (input$sex_filter != "All") {      df &lt;- df[df$SEX == input$sex_filter, ]    }    if (input$race_filter != "All") {      df &lt;- df[df$RACE == input$race_filter, ]    }    return(df)  }) <br>  # ECharts4R plot  output$echarts_plot &lt;- renderEcharts4r({ filtered_data() |&gt;      group_by(DTHFL) |&gt;      e_charts_("AGE") |&gt;      e_scatter_("BMRKR1", symbol_size = 5) |&gt;      echarts4r::e_title("Safety Analysis") |&gt;      echarts4r::e_color(        c("green", "red")      ) |&gt;      echarts4r::e_legend(        formatter = 'Death {name}'      ) |&gt;      e_axis_labels("Age", "Biomarker") |&gt;      e_tooltip(        formatter = JS(          "function(params) {          console.log(params);          return(          'Age: ' + params.value[0] + '' +          'Biomarker Value: ' +          Math.round(params.value[1]) + '' +          'Death: ' + params.seriesName          )}"        )      )  }) <br>  # reactable table  output$reactable_table &lt;- renderReactable({ filtered_data() |&gt;      reactable()  }) </code></pre> <ul><li>This part of the code defines the server-side logic for the Shiny app.</li><li>It creates a reactive expression called <code>filtered_data</code> that filters the clinical data based on user inputs (selected sex and race).</li><li>The <code>renderEcharts4r</code> function generates an interactive scatter plot using echarts4r based on the filtered data. The plot visualizes Age vs Biomarker value. The colours on the plot indicate whether a patient has passed away.</li><li>The renderReactable function generates an interactive table using <code>reactable</code> based on the filtered data.</li></ul> This code sets up a Shiny web application that allows users to select and filter clinical trial data by sex and race, visualizing the data through an interactive scatter plot and an interactive table. The <code>echarts4r</code> package is used for creating the scatter plot and the <code>reactable</code> package is used for generating the interactive table. This interactive dashboard provides a dynamic way to explore and analyze clinical trial data. <h4>Full Code:</h4> <pre><code class="language-r"> --- title: "Clinical Data Analysis with {echarts4r} and {reactable} in a Shiny App" format:  html:    page-layout: custom server: shiny --- <br># Load your clinical trial data remotes::install_github(  "insightsengineering/random.cdisc.data" ) data(  "cadsl", package = "random.cdisc.data" ) <br># Load the required libraries library(shiny) library(echarts4r) library(reactable) library(rmarkdown) library(dplyr) <br> #| panel: sidebar selectInput(  "sex_filter", "Select Sex", choices = c(    "All", unique(as.character(cadsl$SEX))  ) ) selectInput(  "race_filter", "Select Race", choices = c(    "All", unique(as.character(cadsl$RACE))  ) ) <br>#| panel: fill echarts4rOutput("echarts_plot") h4("Data used for plot") reactableOutput("reactable_table") <br> #| context: server filtered_data &lt;- reactive({    df &lt;- cadsl    if (input$sex_filter != "All") {      df &lt;- df[df$SEX == input$sex_filter, ]    }    if (input$race_filter != "All") {      df &lt;- df[df$RACE == input$race_filter, ]    }    return(df)  }) <br>  # ECharts4R plot  output$echarts_plot &lt;- renderEcharts4r({ filtered_data() |&gt;      group_by(DTHFL) |&gt;      e_charts_("AGE") |&gt;      e_scatter_("BMRKR1", symbol_size = 5) |&gt;      echarts4r::e_title("Safety Analysis") |&gt;      echarts4r::e_color(        c("green", "red")      ) |&gt;      echarts4r::e_legend(        formatter = 'Death {name}'      ) |&gt;      e_axis_labels("Age", "Biomarker") |&gt;      e_tooltip(        formatter = JS(          "function(params) {          console.log(params);          return(          'Age: ' + params.value[0] + '' +          'Biomarker Value: ' +          Math.round(params.value[1]) + '' +          'Death: ' + params.seriesName          )}"        )      )  }) <br>  # reactable table  output$reactable_table &lt;- renderReactable({ filtered_data() |&gt;      reactable()  }) </code></pre> Finally, click on <strong>“Run Document”</strong> at the top of the page. Then open the port where the app is deployed on your browser. <img class=" wp-image-22063" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b01972241e6b4b2f013e19_Untitled-6.webp" alt="A screenshot of an R console output displaying the loading of the 'shiny' package, attachment of the 'dplyr' package, and messages about masked objects from the 'stats' and 'base' packages, followed by an IP address indicating a Shiny app is listening on a local server." width="587" height="495" /> R Console Output with Shiny App Initialization In this case, it is http://127.0.0.1:7341. Open this link on the browser. And Voila! We have a Shiny App launched from a Quarto document. Yes, it's that easy! [video width="1440" height="610" webm="https://wordpress.appsilon.com/wp-content/uploads/2023/11/quarto.webm" loop="true" autoplay="true"][/video] <h2 id="conclusion">Conclusion</h2> In our exploration of clinical research, we've uncovered the remarkable potential of Shiny and Quarto to revolutionize the way we collect, analyze and report data. Clinical research, a cornerstone of medical progress, demands tools that can keep pace with the complexity of healthcare data and the urgency of patient care. Shiny and Quarto rise to this challenge with remarkable capabilities. <strong>The transformative power of Shiny and Quarto in clinical research is undeniable. </strong>Their ability to make data come to life, facilitate collaboration and expedite decision-making is a game-changer. The journey ahead is filled with exciting possibilities, and we encourage you to embark on it with enthusiasm and dedication. <strong>Embrace interactive reporting</strong>, explore its potential and be part of the movement that is reshaping the future of healthcare research for the betterment of all. <h2 id="resources">Resources</h2> <h3>Shiny Resources</h3> <ul><li><strong>Official Shiny Documentation:</strong> The official documentation provides comprehensive information on getting started with Shiny, building applications and advanced topics. You can find it at <a href="https://shiny.posit.co/" target="_blank" rel="noopener noreferrer">Shiny Documentation</a>.</li><li><strong>Shiny Tutorial:</strong> RStudio offers a helpful Shiny tutorial that covers the basics of creating interactive web applications. You can access it at <a href="https://shiny.posit.co/r/getstarted/shiny-basics/lesson1/index.html" target="_blank" rel="noopener noreferrer">Shiny Tutorial</a>.</li><li><strong>Shiny Gallery:</strong> The Shiny Gallery showcases a wide range of Shiny applications and examples, offering inspiration and practical use cases. Explore it at <a href="https://shiny.posit.co/r/gallery/" target="_blank" rel="noopener noreferrer">Shiny Gallery</a>.</li></ul> <h3>Quarto Resources</h3> <ul><li><strong>Official Quarto Documentation:</strong> The official documentation provides detailed guidance on using Quarto for creating dynamic documents. You can find it at <a href="https://quarto.org/docs/" target="_blank" rel="noopener noreferrer">Quarto Documentation</a>.</li><li><strong>Quarto GitHub Repository:</strong> The GitHub repository contains the latest updates, issues and community contributions related to Quarto. Visit it at <a href="https://github.com/quarto-dev/quarto" target="_blank" rel="noopener">Quarto GitHub Repository</a>.</li></ul> <h3>Pharmaceutical Domain Resources</h3> <ul><li><strong>FDA's Regulatory Guidelines:</strong> The U.S. Food and Drug Administration (FDA) provides comprehensive guidelines and regulations for pharmaceutical research and development. Access these guidelines at <a href="https://www.fda.gov/drugs/guidance-compliance-regulatory-information" target="_blank" rel="noopener noreferrer">FDA Regulations and Guidances</a>.</li><li><strong>Pharmaceutical Industry Journals:</strong> Journals such as <em>"Nature Reviews Drug Discovery"</em><em>"Clinical Pharmacology &amp; Therapeutics"</em> and <em>"Pharmaceutical Research"</em> provide valuable insights into the latest research and trends in the pharmaceutical domain.</li><li><strong>Pharmaceutical News and Publications:</strong> Websites like <em>"Pharmaceutical Technology"</em> and <em>"Pharmaceutical Journal"</em> offer news, articles and publications related to the pharmaceutical industry.</li><li><strong>ClinicalTrials.gov:</strong> This resource provides a comprehensive database of clinical trials in various therapeutic areas. It can be useful for staying updated on ongoing research. Explore it at <a href="https://clinicaltrials.gov/" target="_blank" rel="noopener noreferrer">ClinicalTrials.gov</a>.</li><li><strong>Pharmaceutical Conferences and Events:</strong> Attending conferences and events in the pharmaceutical industry, such as those organized by the <em>Drug Information Association (DIA)</em> or the <em>American Association of Pharmaceutical Scientists (AAPS)</em> can provide networking opportunities and access to the latest research.</li></ul> These resources should serve as valuable references for those interested in Shiny, Quarto and the pharmaceutical domain, whether you're looking to develop interactive applications, create dynamic documents, or stay informed about industry trends and regulations. <h2 id="connect">Connect with Us</h2> We at Appsilon are dedicated advocates of Shiny and Quarto, driven by a profound fascination for their potential in clinical research. With 10+ years of hands-on experience in utilizing these tools, we've witnessed their transformative capabilities in enhancing data analysis and reporting in the medical field. If you're eager to explore Shiny, Quarto, or have questions and insights to share, <a href="https://appsilon.com/#contact" target="_blank" rel="noopener">we’re here to connect, collaborate, and empower your journey</a>. <blockquote>Interested in enhancing data integrity in life sciences? Discover the role of <a href="https://appsilon.com/exploring-r-package-validation-in-life-sciences/" target="_blank" rel="noopener">R package validation in ensuring reliable and compliant data analysis in this detailed exploration.</a></blockquote>

Contact us!
Damian's Avatar
Damian Rodziewicz
Head of Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
shiny
quarto
r
data analytics
life sciences