Skip to content

Instantly share code, notes, and snippets.

@bretonics
Last active March 20, 2018 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bretonics/c4f82f3db918779fae7a4a136b02ace4 to your computer and use it in GitHub Desktop.
Save bretonics/c4f82f3db918779fae7a4a136b02ace4 to your computer and use it in GitHub Desktop.
Shiny Framework Function Reference Sheet

Shiny Reference Sheet

A web application framework for R quick function reference sheet.

Input

Function Creates
actionButton() Action button element
submitButton() Submit button element
checkboxInput() Checkbox input element
checkboxGroupInput() Checkbox group input element
dateInput() Date input element
dateRangeInput() Date range input element
fileInput() File input element
numericInput() Numeric input element
passwordInput() Password input element
radioButtons() Radio button element
selectInput() Select input element
sliderInput() Slider input element
textInput() Text input element

Display Output

Function Creates
renderDataTable() An interactive table A plot (from a data frame, matrix, or other table-like structure)
renderImage() An image (saved as a link to a source file)
renderPlot() A Plot
renderPrint() A code block of printed output
renderTable() A table (from a data frame, matrix, or other table-like structure)
renderText() A character string
renderUI() A Shiny UI element

Output

Function Inserts
dataTableOutput() An interactive table image
htmlOutput() Raw HTML
imageOutput() Image
plotOutput() Plot
tableOutput() Table
textOutput() Text
uiOutput() A Shiny UI element
verbatimTextOutput() Text

Reactive

  1. Code chunk build/rebuild object
  2. Object responds to changes in set of reactive values
Function Description
reactive() Reactive object
isolate() Non-reactive object
observeEvent() Trigger code to run on server, specify reactive value precisely
observe() Trigger code to run on server, more general

Delay

Function Description
eventReactive() Reactive expression only responds to specific values

Managing State

Function Description
reactiveValues() List of reactive values to manipulate programmatically ( usually with observeEvent() )

Type names(tags) to get all available HTML tags.

Some tags functions come with a wrapper function, so you do not need to call tags$.

Function Creates
a() A Hyperlink
br() A line break
code() Text formatted like computer code
em() Italicized (emphasized) text
h1(), h2(), h3(), h4(), h5(), h6() Headers (First level to sixth)
hr() A horizontal rule (line)
img() An image
p() A new paragraph
strong() Bold (strong) text

Layout

Function Creates
fluidRow() Adds rows to the grid
column() Adds columns within a row
sidebarLayout() Use with sidebarPanel() and mainPanel() to divide app into 2 sections
fixedPage() Creates page with default width of browser window
fixedRow() Adds row to grid using fixedPage()
navbarPage() Replaces fluidPage(). Combines tabs into single page

library(shinydashboard)

A dashboard like layout package of functions for building dashboards with Shiny.

Panels

Group elements into single unit for aesthetics or functionality.

Function Creates
absolutePanel() Panel position set rigidly (absolutely), not fluidly
conditionalPanel() A JavaScript expression determines whether panel is visible or not
fixedPanel() Panel is fixed to browser window and does not scroll with the page
headerPanel() Panel for displaying a sidebar of inputs, used with pageWithSidebar()
inputPanel() Panel with grey background, suitable for grouping inputs
mainPanel() Panel for displaying output, used with pageWithSidebar()
navlistPanel() Panel for displaying multiple stacked tabPanels(). Uses sidebar navigation
sidebarPanel() Panel for displaying a sidebar of inputs, used with pageWithSidebar()
tabPanel() Stackable panel. Used with navlistPanel() and tabsetPanel()
tabsetPanel() Panel for displaying multiple stacked tabPanels(). Uses tab navigation
titlePanel() Panel for the app’s title, used with pageWithSidebar()
wellPanel() Group elements into a grey background ("well")

Other

Function Inserts
HTML() Raw HTML

Adding Images

To add an image from a file, save the file in a subdirectory named www in app directory.

CSS

  1. Link to external CSS file
    • Place .css files in www app directory.

      • theme argument inside fluidPage() set to .css file for whole app to use
      ui <- fluidPage(
          theme = "bootswatch-cerulean.css",
          ) 
      
    • Place link in the app's header with tags$head() and tags$link() to file.

      • Creates header section in app with rel, type, and href arguments.
      ui <- fluidPage(
          tags$head(
              tags$link(
                  rel = "stylesheet",
                  type = "text/css",
                  href = "file.css"
                  )
              ) 
          )
      
        
2. Write global CSS in header
    - Use `tags$head()` and `tags$style` and `HTML()`
    ```
    ui <- fluidPage(
        tags$head(
            tags$style( HTML(" 
                p{
                    color:red;
                }
                "))
        ) 
    )
    ```
    - Use `includeCSS()` with file in app directory (not necessary in www) by copying all contents to webpage.
    ```
    ui <- fluidPage(
            includeCSS("file.css")
        )
    ```

3. Write individual CSS in tag's style attribute
    ```
    ui <- fluidPage(
            tags$h1("Title", style = "color:red;")
        )
    ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment