Visual enhancements

Case Studies: Building Web Applications with Shiny in R

Dean Attali

Shiny Consultant

Shiny tables

tableOutput("table")

output$table <- renderTable({ gapminder })

chapter3_4_visual_enhancements.003.png

Case Studies: Building Web Applications with Shiny in R

Make better tables with DT

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.004.png

Case Studies: Building Web Applications with Shiny in R

Make better tables with DT

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.005.png

Case Studies: Building Web Applications with Shiny in R

Make better tables with DT

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.006.png

Case Studies: Building Web Applications with Shiny in R

Make better tables with DT

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.007.png

Case Studies: Building Web Applications with Shiny in R

Make better tables with DT

DT::dataTableOutput("table")

output$table <- DT::renderDataTable({ gapminder })

chapter3_4_visual_enhancements.008.png

Case Studies: Building Web Applications with Shiny in R

Split the UI into tabs

chapter3_4_visual_enhancements.009.png

Case Studies: Building Web Applications with Shiny in R

Split the UI into tabs

chapter3_4_visual_enhancements.010.png

Case Studies: Building Web Applications with Shiny in R

Split the UI into tabs

tabPanel(title = "tab 1", "content goes here")

tabPanel(title = "tab 2", "second tab", plotOutput("plot"))
fluidPage(

tabsetPanel(
tabPanel(title = "tab 1", "first tab content goes here"), tabPanel(title = "tab 2", "second tab", plotOutput("plot")), tabPanel(title = "tab 3", textInput("text", "Name", ""))
)
)

chapter3_4_visual_enhancements.016.png

Case Studies: Building Web Applications with Shiny in R

CSS: Fine-tune your app's look

  • Cascading Style Sheets
  • Markup language to customize look of any element in webpage
    • Shiny UI is a webpage
  • Background color, text color, text size, whitespace, fonts, ...
Case Studies: Building Web Applications with Shiny in R

CSS syntax

  • CSS rules syntax

    #ID {
      property: value;
      property: value;
      ...
    }
    
  • ID is element ID to apply the style to

  • To add CSS to Shiny, use tags$style()

    ui <- fluidPage(
      tags$style("
        #ID {
          property: value;
        }
      ")
    )
    
Case Studies: Building Web Applications with Shiny in R

CSS example

ui <- fluidPage(
  textInput("name", "Enter your name", "Dean"),
  tableOutput("table")
)

chapter3_4_visual_enhancements.029.png

Case Studies: Building Web Applications with Shiny in R

CSS example

ui <- fluidPage(
  textInput("name", "Enter your name", "Dean"),
  tableOutput("table")
)

chapter3_4_visual_enhancements.030.png

Case Studies: Building Web Applications with Shiny in R

CSS example

ui <- fluidPage(
  textInput("name", "Enter your name", "Dean"),
  tableOutput("table")
)

chapter3_4_visual_enhancements.031.png

Case Studies: Building Web Applications with Shiny in R

CSS example

ui <- fluidPage(
  textInput("name", "Enter your name", "Dean"),
  tableOutput("table")
)

chapter3_4_visual_enhancements.032.png

Case Studies: Building Web Applications with Shiny in R

CSS example

css <- "

#name { color: red; }
#table { background: yellow; font-size: 24px; }
"
ui <- fluidPage(

tags$style(css),
textInput("name", "Enter your name", "Dean"), tableOutput("table") )
Case Studies: Building Web Applications with Shiny in R

Let's practice!

Case Studies: Building Web Applications with Shiny in R

Preparing Video For Download...