GenEst - 4. Graphic User Interface

Juniper L. Simonis

2021-06-16

Overview

This document describes the codebase used to create the GenEst Graphic User Interface (GUI). The Genest GUI is coded in HTML via external R packages (DT, htmltools, shiny, shinyjs, as well as a number of internal functions to facilitate a simple, human-readable codebase underlying the app. The goal being to allow GenEst to evolve as fluidly as possible at the user interface.

Execution

The GUI is executed locally or as a deployed app following the basic approach of shiny applications. For ease of implementation, we have created an overall function to intialize the app, runGenEst(), which calls both the server and UI codebases. Like most vintage Shiny apps, we employee the two-file system, including a ui.R and server.R script, although each script is Spartan. The ui.R script includes a single call to the GenEstUI(appType) function, which starts the cascade of HTML-generating functions outlined in UI Function Hierarchy. The server.R script includes a single reference (not a call) to the function GenEstServer, which is detailed in Server Function Hierarchy.

User Interface

UI Function Hierarchy

The GenEst User Interface is constructed in HTML using pages, panels, tabs, and widgets. The code is parsed into a series of hierarchical functions to facilitate readability and mobility of specific UI components.

UI Widgets

We have coded up a number of widget functions, some of which are simple wrappers on shiny functions that help reduce code clutter, and others of which are custom HTML (e.g., for model selection), but which are still nonetheless wrapped over shiny widgets:

A major need for widgets is having a simple condition wrapped on it, such that the widget is within a conditional panel, defined by some other input or output variable. To facilitate coding of these widgets, we have made a function widgetMaker, which is a generalized constructor function.

UI Panels

Similarly to the input widgets, we have coded up a number of output panel functions that help direct traffic in the building on the HTML document. These functions are generalized to the suite of possible options for panels currently needed by leveraging the basic template approach with limited variation.

UI Content

There is a fair amount of (mostly) static content, which we have contained wihtin functions to reduce overall code clutter. These functions primarily dictate content within the “Help” tab’s subtabs.

Server Functionality

Reactivity

The server-side functionality operates using Shiny’s reactive programming framework. In particular, we include a main reactiveValues list called rv, that, in addition to the standard input and output lists is passed among functions throughout the app. The rv list holds all of the reactive values currently being used by the application.

Server Function Hierarchy

The GenEst server code is a relatively flat hierarchy, especially in comparison to the UI code. In particular, after a brief set of preamble functions for preparing objects and options, GenEstServer makes many calls to observeEvent, the reactive observation function, one call for each of the possible events in the application (data load, model run or clear, column selection, clear of contents). Each call also includes an evaluation of the held-back “handler” code for the event returned by the function reaction, with the handler being the code that is to be evaluated when the event is observed. The expression is held-back in reaction to minimize scoping issues associated with message-related functions.

The reaction function is, essentially, a parsed-text-generating function. Depending upon the specific event (eventName, the only input), the necessary set of function calls (messages for running, running the code, messages for when done) is prepared for evaluation. The main function used to do things within the handler code (when the event occurs) is eventReaction, which calls three functions: update_rv, update_output, and update_input, in that order (updating the output depends on the rv being updated already and updating the input requires both the rv and output to be up-to-date):

Because of the scoping set-up for Shiny apps, there is no need to assign the returned elements for update_rv and update_output to anything, and update_input works through session to direct its updates to the application.

Each of the three functions takes eventName as the first argument, which is used to toggle amongst the possible actions to be taken with respect to each of the lists. That is, each of the three update_ functions contains a large internal set of routines, and only the relevant ones are called for a given function. This occurs via simple conditional code blocks (“if the eventType is this, do this”) for each of the possible events, thereby reducing the number of specific functions, but increasing the size of the key functions. Within each of the three functions, some of the events trigger a substantial amount of code while others only trigger a few (or no) lines. Similarly, some of the handler expressions take virutally no time to run, while others take a few minutes.