Advanced features to improve your plot

Case Studies: Building Web Applications with Shiny in R

Dean Attali

Shiny Consultant

Colour input

library(colourpicker)

colourInput("col", "Select a colour", value = "orange")

chapter2_4_advanced_features_to_improve_your_plot.006.png

Case Studies: Building Web Applications with Shiny in R

Outputs can have arguments

plotOutput(outputId, width = "100%", height = "400px",
           click = NULL, dblclick = NULL, hover = NULL,
           hoverDelay = NULL, hoverDelayType = NULL, 
           brush = NULL, clickId = NULL, hoverId = NULL,
           inline = FALSE)
Case Studies: Building Web Applications with Shiny in R

Plot output arguments

plotOutput("plot1", width = 200, height = 400)
plotOutput("plot2", width = 400, height = 200)

chapter2_4_advanced_features_to_improve_your_plot.008.png

Case Studies: Building Web Applications with Shiny in R

Interactive plots with plotly

  • Many packages for interactive plots
  • plotly is popular choice
  • ggplotly():
    • ggplot2 plot ⇒ interactive
p <- ggplot(gapminder, 
          aes(gdpPercap, lifeExp)) +
     geom_point() +
     scale_x_log10()

library(plotly)
ggplotly(p)

chapter2_4_advanced_features_to_improve_your_plot.015.png

Case Studies: Building Web Applications with Shiny in R

Interactive plots with plotly

  • Many packages for interactive plots
  • plotly is popular choice
  • ggplotly():
    • ggplot2 plot ⇒ interactive
p <- ggplot(gapminder, 
          aes(gdpPercap, lifeExp)) +
     geom_point() +
     scale_x_log10()

library(plotly)
ggplotly(p)

chapter2_4_advanced_features_to_improve_your_plot.016.png

Case Studies: Building Web Applications with Shiny in R

Interactive plots with plotly

  • Many packages for interactive plots
  • plotly is popular choice
  • ggplotly():
    • ggplot2 plot ⇒ interactive
p <- ggplot(gapminder, 
          aes(gdpPercap, lifeExp)) +
     geom_point() +
     scale_x_log10()

library(plotly)
ggplotly(p)

chapter2_4_advanced_features_to_improve_your_plot.017.png

Case Studies: Building Web Applications with Shiny in R

Interactive plots with plotly

  • Many packages for interactive plots
  • plotly is popular choice
  • ggplotly():
    • ggplot2 plot ⇒ interactive
p <- ggplot(gapminder, 
          aes(gdpPercap, lifeExp)) +
     geom_point() +
     scale_x_log10()

library(plotly)
ggplotly(p)

chapter2_4_advanced_features_to_improve_your_plot.018.png

Case Studies: Building Web Applications with Shiny in R

Plotly in Shiny

  • Incorrect
plotOutput("plot")
renderPlot(ggplotly(p))
  • Correct
plotlyOutput("plot")
renderPlotly(ggplotly(p))
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...