Eric Nantz
Eric Nantz
Follow Setup Procedure to connect with the workshop resources:
Production has more than one meaning for Shiny apps
The tooling & principles discussed in this workshop will guide you to the destination
We will build a Shiny application simclindata.shiny
in the spirit of many Life Sciences projects:
R is the standard-bearer for data analysis tooling
Not just providing another interface for data analysis
You are engineering an entire workflow
These principles can guide (future) you on the right path:
Others not covered today
… at least for production-quality apps!
Imagine your application is working great!
ggplot2
version 0.9.3
ggplot2
version 1.0.0
{renv}
Create reproducible environments for your R projects.
{packrat}
Upon initializing a project:
.Rprofile
to activate custom package library on startuprenv.lock
to describe state of project libraryrenv/library
to hold private project libraryrenv/activate.R
performs activation{golem}
Opinionated framework for building production-grade Shiny applications as R packages
{usethis}
& {devtools}
🤔 id
moduleServer()
: Encapsulate server-side logic with namespace applied.tagList()
of inputs, output placeholders, and other UI elementsartServer <- function(id, df, title = "My Plot") {
moduleServer(id,
function(input, output, session) {
user_selections <- reactive({
list(input1 = input$input1, input2 = input$input2)
})
output$plot1 <- renderPlot({
ggplot(df(), aes(x = x, y = y)) +
geom_point() +
ggtitle(title)
})
user_selections
}
)
}
artServer <- function(id, df, title = "Amazing") {
moduleServer(id,
function(input, output, session) {
user_selections <- reactive({
list(input1 = input$input1,
input2 = input$input2)
})
output$plot1 <- renderPlot({
ggplot(df(), aes(x = x, y = y)) +
geom_point() +
ggtitle(title)
})
user_selections
}
)
}
df
df()
user_selections
, user_selections()
Applying {golem}
& {renv}
to our simclindata.shiny application
{dplyr}
Jedi{DBI}
Unified set of methods & classes bridging interfacing R to database management systems (DBMS)
You have used connections in R (and may not realize it)
read.csv("path/to/file.csv", stringsAsFactors = FALSE)
readr::read_csv("path/to/file.csv")
openxlsx::write.xlsx(df, file = "/path/to/file.xlsx")
Behind the scenes: connections are dynamically created (and terminated) during file input/output.
{dplyr}
Skillz{dbplyr}
provides automatic translation from dplyr syntax to SQL statements
{DBI}
{dplyr}
SkillzLogical ways to manage connections when developing solo
{pool}
!Abstraction layer on top of database connection objects
Optimize backend calculations in {simclindata.shiny}
with SQLite database
dept_choices <- c("Ancient Near Easter Art", "American")
selectInput(
"dept",
"Select Department",
choices = dept_choices
)
<div class="form-group shiny-input-container">
<label class="control-label" id="dept-label" for="dept">
Select Department
</label>
<div>
<select id="dept" class="form-control">
<option value="Ancient Near Easter Art" selected>Ancient Near Easter Art</option>
<option value="American">American</option>
</select>
</div>
</div>
Empowers users across spectrum of design experience
Set of rules that define how HTML content is presented in the browser
Streamline the design of {simclindata.shiny}
with a pinch of customization