This vignette describes the intended workflow and usage of the wilson package for building an application and provides a simple example.
Prerequisites:
The workflow of a wilson-application can roughly be divided into three basic steps:
But depending on the actual implementation neither the order nor the number of steps are set. Resulting in enhanced usability as for example the filter can be changed at any given time.
In this example we will create a wilson-application with a static dataset, a single visualization method and a preceding filter, separated into a Filter and a Visualization tab.
So to start we first import the needed packages and afterwards define the application interface:
library(shiny)
library(shinydashboard)
library(wilson)
# Define UI for application
ui <- dashboardPage(
header = dashboardHeader(disable = TRUE),
sidebar = dashboardSidebar(disable = TRUE),
body = dashboardBody(
tags$style(type = "text/css", "body {padding-top: 50px;}"),
navbarPage(
title = "wilson example",
position = "fixed-top",
tabPanel(title = "Filter",
# Load filter UI
featureSelectorUI(id = "filter")),
tabPanel(title = "Visualization",
# Load scatterplot UI
scatterPlotUI(id = "scatter"))
)))
This code creates an UI with two tabs. The first tab with the title Filter contains the filter UI called with featureSelectorUI()
whereas the UI needed for a scatterplot called with scatterPlotUI()
is enclosed by the second tab (Visualization).
Second the server function needs to be as follows:
# Define server logic required for filtering and plotting
server <- function(input, output, session) {
# load/ parse data
# change this path to match your file location
data <- parser("../wilson-apps/wilson-basic/data/A_RNAseq_Zhang_2015.se")
# Load filter server logic
filtered_data <- callModule(module = featureSelector, id = "filter", clarion = data)
# Load scatterplot server logic
callModule(module = scatterPlot, id = "scatter", clarion = reactive(filtered_data()$object))
}
# Run the application
shinyApp(ui = ui, server = server)
The server reacts to user interactions with the interface. Once started it will first parse the given clarion file into a clarion object, performing validation steps in the process. Next the server functions of the necessary modules defined in the UI (notice the matching ids) are loaded. Whereas the filter module bluntly accepts the data object with clarion = data
the plot module receives its data via clarion = reactive(filtered_data()$object)
. Wrapping in reactive()
is due to the fact, that the filtered data object returned from the filter module is in a reactive context which essentially means shiny ‘knows’ when this variable changes. Read more about shiny’s reactivity system here.
For a more advanced example of a wilson-application see the wilson-basic app in our wilson-apps repository.