library(shiny)
runExample("01_hello")
Shiny Web App from the New File menufluidPage: renders a webpage that dynamically resizes to fit browser (can also use navbarPage, which accommodates multiple webpages)
titlePanel: page titlesidebarLayout: creates main panel for outputs and sidebar for input widgets (can also use fluidRow/column to create a custom layout)
sidebarPanel: render sidebar
sliderInput: widget that collects user inputmainPanel: render main panel
plotOutput: render output plotinput: list of inputs with names matching widget inputIdsoutput: list of reactive outputs with names that match outputIds of ui outputslibrary(shiny)
ui <- fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "bins", label = "Number of bins:", min = 1, max = 50, value = 30)
),
mainPanel(
plotOutput(outputId = "distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = "#75AADB", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")
})
}
navbarPage allows inclusion of multiple tabPanel elements, each having it’s own sidePanel/mainPanel (or other layout)
navbarMenu elements, that create drop-down menus with additional tabPanelstabsetPanel allows multiple tabPanel elements within a mainPanel (sharing the same sidePanel)
conditionalPanel allows sidebarPanel elements to change between tabsnavlistPanel is similar to tabsetPanel, but the list of tabPanels is in the sidebar rather than across the top of the main panel (similar to a floating table of contents in a rMarkdown document)conditionalPanel allows different sidebars for each tabobserve can be used to reactively change the state of a ui widget (eg; update slider based on typed value)
observe({
updateSliderInput(session, "pvalue", value = input$typedPval)
})
req can be used prevent rendering output until input has been selected
output$Plot1 <- renderPlot({
req(input$geneID)
MakePlot(input$geneID , table1)
})
validate can be used to raise an error if inputs are incorrect
output$Plot1<- renderPlot({
validate(
need(input$Table1_rows_selected != "", "Please select a row from the table")
)
MakePlot(input$Table1_rows_selected , table1)
})
output$Table1 <- DT::renderDataTable({
DT::datatable(table1, caption = 'Big ass table of results')
})
bsCollapse creates collapsable panelsbsTooltip and bsPopover to add text popups to input widgets and outputs respectivelybsModal to put output in a popup windowRun as much code as possible server function / render function

Use reactive to avoid redoing all processing when some inputs change
reactive can be used to store inputs that require a lot of processingreactive function will not rerundataInput <- reactive({
getSymbols(input$symb, src = "google",
from = input$dates[1],
to = input$dates[2],
auto.assign = FALSE)
})
output$plot <- renderPlot({
chartSeries(dataInput(), theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})
genotypes <- system(paste("bcftools view -H -r", snp_pos, "./Data/combined_filtered.vcf.gz"), intern=TRUE) %>%
str_split('\t')
runGitHub function that allows apps to be run directly from github, but I’m not sure if it would work with a private repo