knitr::opts_knit$set(root.dir = file.path(SOUNDBoard:::.options$get("resources"), "html"))
This vignette provides a quick tour of SOUNDBoard. There are three steps to creating a SOUND Board Report: assembly, presentation, and deployment
Load the SOUNDBoard package
suppressPackageStartupMessages({ library(SOUNDBoard) library(shiny) })
Create a SOUNDManager()
. The first argument is the path to the local
version of your report and its assets. We use a temporary location for
the vignette. The second (optional) argument is a file defining SQL
tables board
, cases
, and assays
via schemas. The schemas are
used to initialize the data base used to store board information.
x <- SOUNDManager(tempfile()) x
Now create records corresponding to boards and cases you are tracking.
tbl(x, "board") <- list( board_uid = "MitoNET", description = "Clinical management of rare genetic disorders" ) tbl(x, "cases") <- list( board_uid = "MitoNET", case_uid = "PATIENT_1", age = 36, sex = "Male" )
Add 'assays' for cases under investigation. Each assay should be a
single R object, file, etc. Use manage()
to serialize the
object. We provide two examples, to illustrate assays that might be
summarized as data frames or images.
tbl(x, "assay") <- list( case_uid = "PATIENT_1", assay = "RNA candidates", description = "RNA candidate genes derived from analysis ...", resource = manage(x, data.frame()) ) tbl(x, "assay") <- list( case_uid = "PATIENT_1", assay = "data.frame", description = "Demonstrating data frame management", resource = manage(x, mtcars) ) tbl(x, "assay") <- list( case_uid = "PATIENT_1", assay = "ggplot", description = "Demonstrating ggplot management", resource = manage(x, ggplot2::qplot(hp, mpg, data=mtcars)) )
Assays can be complicated, e.g., an entire shiny application:
## create a shiny application myapp <- ShinyAppWidget( shinyApp( ui = bootstrapPage( numericInput('n', 'Number of obs', 100), plotOutput('plot') ), server = function(input, output) { output$plot <- renderPlot({ hist(runif(input$n)) }) } ) )
Add the shiny app as a managed ShinyWidget()
assay
tbl(x, "assay") <- list( case_uid = "PATIENT_1", assay = "shiny", description = "Demonstrating shiny application", resource = manage(x, myapp) )
Review the information under management
x tbl(x, "board") tbl(x, "cases") tbl(x, "assay")
Prepare a report by extracting relevant rows from the board, cases, or
assay tables, and present them in a markdown document with
sbreport()
. The code chunks would typically include echo=FALSE
. Here
we present the code chunks with eval=FALSE
, and then again with
echo=FALSE
to see the results in this document.
'''{r} tbl(x, "board") %>% filter(board_uid == "MitoNET") %>% sbreport() tbl(x, "cases") %>% filter(case_uid == "PATIENT_1") %>% select(-board_uid) %>% sbreport() ''' '''{r} tbl(x, "assay") %>% filter(case_uid == "PATIENT_1", assay == "data.frame") %>% sbreport() ''' '''{r} tbl(x, "assay") %>% filter(case_uid == "PATIENT_1", assay == "ggplot") %>% sbreport() ''' '''{r} tbl(x, "assay") %>% filter(case_uid == "PATIENT_1", assay == "shiny") %>% sbreport() '''
tbl(x, "board") %>% filter(board_uid == "MitoNET") %>% sbreport() tbl(x, "cases") %>% filter(case_uid == "PATIENT_1") %>% select(-board_uid) %>% sbreport()
Demonstrating plot (ggplot2 / plotly) management
tbl(x, "assay") %>% filter(case_uid == "PATIENT_1", assay == "ggplot") %>% sbreport()
Demonstrating data frame (data.frame()
/ DT) management
tbl(x, "assay") %>% filter(case_uid == "PATIENT_1", assay == "data.frame") %>% sbreport()
Embedded apps: more advanced calculations can call back into R.
tbl(x, "assay") %>% filter(case_uid == "PATIENT_1", assay == "shiny") %>% sbreport()
manager <- SOUNDManager( x, host = "localhost", port = "3838", path = "SOUNDBoard", username = "soundboard" ) deploy(manager)
SOUNDWidget
The SOUNDWidget()
function allows users to create alternative ways
to store, load, and report different data types. The argument requires
a single argument, the name of the widget, and three optional
arguments. The optional arguments are functions that describe how the
content of the widget is to be saved to disk (e.g., saveRDS()
),
loaded from disk (e.g., readRDS()
) and presented in the report
(e.g., DT::datatable()
). Here we create a simple widget that manages
a data.frame()
, reporting it as an interactive DT datatable()
(this behavior is provided by default; the widget is developed for
illustration only).
DTWidget <- SOUNDWidget( "DTWidget", save = function(x, file) saveRDS(x, file), load = function(x, file) readRDS(file), report = function(x) DT::datatable(sbresource(x)) )
The SOUNDWidget()
function returns a constructor, to be used with
the object to be manipulated, e.g., using the USArrests
built-in
data set.
arrests <- DTWidget(USArrests) arrests head(sbresource(arrests))
The functionality can be tested directly
fl <- tempfile() sbsave(arrests, fl) reloaded <- sbload(DTWidget(), fl)
Running the sbreport()
command generates an html page containing the
USArrests
data set as an interative html-based table.
sbreport(reloaded)
The new widget can be incorporated into a report as above, e.g., adding to the data base
tbl(x, "assay") <- list( case_uid = "PATIENT_1", assay = "arrests", description = "Demonstrating custom widget management", resource = manage(x, arrests) )
or including in the report
tbl(x, "assay") %>% filter(assay == "arrests") %>% sbreport()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.