Introduction and Motivation


  • Interactive applications and dashboards are valuable tools for presenting complex research data in an intuitive and engaging way, particularly for non-specialist audiences.
  • Open science benefits from such applications because they can help increase public understanding, enhance the visibility of research, and support informed discourse on topics of public interest.
  • Shiny is an R package that allows researchers to create interactive web applications and dashboards without needing to know web technologies like HTML, CSS, or JavaScript.

Shiny Fundamentals


  • The fundamental building blocks of all Shiny applications are the user interface (UI) and the server. Shiny apps are launched by combining the UI and server with the shinyApp() function.
  • Output functions serve two purposes: in the UI, they act as placeholders for content; in the server, their corresponding render functions generate content to be displayed. It’s possible to build a static Shiny application using only outputs, without any inputs.
  • Input functions create various widgets (such as text boxes, sliders, menus etc.) that allow users to interact with an application by specifying input values. By default, changes in inputs automatically trigger updates in outputs—this behavior is called reactivity. Input values are referenced in the server using their unique IDs.
  • Reactive expressions (also known as reactive conductors) created with reactive() sit between inputs and outputs, allowing you to process or transform input values before they’re displayed. They help reduce duplication and improve performance.
  • Observers created with observe() let you perform side effects—tasks that respond to changes but do not return values (e.g., resetting inputs, enabling/disabling buttons, or saving files). They affect app behavior rather than generating output.
  • Functions such as eventReactive() and observeEvent() provide more control over when reactivity occurs. They are useful for delaying updates until a specific event (like a button click) happens. Use eventReactive() when producing outputs and observeEvent() for behavior changes that don’t involve rendering output.
  • Layouts and themes help organize and style your app. Use sidebar layout and tabs to arrange components clearly. Style templates from the shinythemes package can give your app a polished look with minimal effort.

Shiny Data Applications


  • Shiny applications can offer an accessible and interactive entry point into tabular datasets; you can build such applications using only the concepts and tools introduced in the previous Episode
  • R Studio’s Shiny web application template can help save you time in writing applications; start with the template, and swap in the functions needed for your specific applications
  • It can be helpful to verbally conceptualize and outline your application before writing the relevant code
  • To add tabular information to the Shiny application UI, it’s recommended that you use the DT package’s dataTableOutput() (in the UI) and renderDataTable() (in the server) functions.

Shiny Data Dashboards


  • shinydashboard is a package that makes it easier to develop data dashboards using Shiny principles
  • We can think of a data dashboard as a specific type of data application with a more structured layout, and the ability to display larger amounts of information in context
  • The basic principles involved in building a dashboard with shinydashboard are the same as those for any Shiny application, but shinydashboards has unique functions associated with the dashboard layout
  • In shinydashboard, the UI is divided into three main parts: dashboardHeader(), dashboardSidebar(), and dashboardBody(). These allow for a clear separation of the header, navigation sidebar, and main content body, which contributes to a structured, user-friendly layout.
  • shinydashboard makes it easy to organize content using boxes, value boxes, and fluid rows. Each of these can be customized with specific widths to ensure an optimal layout for displaying information like charts, tables, or textual content.
  • Just like any other Shiny application, dashboards can include interactive elements like inputs (e.g., sliders, dropdowns, checkboxes) to filter or modify the displayed data in real time. You can create dynamic outputs using render functions, such as renderPlot() that are familiar from before, as well as render functions unique to shinydashboard such as renderValueBox().

Publishing Shiny Applications


  • There are a variety of ways to publish your Shiny applications and dashboards to the web, depending on your needs
  • The most intuitive and beginner-friendly publication platform is Posit’s shinyapps.io
  • Before being able to deploy your apps to shinyapps.io, you must set up an account, and configure rsconnect
  • After this initial set up, you can deploy your application by passing the filepath to the application directory (which contains the app.R file containing your application code, as well as any other relevant dependencies) as an argument to rsconnect’s deployApp() function.
  • Once the application is deployed, you can go to your shinyapps.io account page (and particularly the page’s “Application View”) to retrieve the published application’s url, track usage statistics, and manage your application (for example, archive or delete it when you no longer want it publicly available).