options(htmltools.dir.version = FALSE)
# see: https://github.com/yihui/xaringan
# install.packages("xaringan")
# see: 
# https://github.com/yihui/xaringan/wiki
# https://github.com/gnab/remark/wiki/Markdown
options(width=110)
options(digits = 4)
knitr::opts_chunk$set(comment=NA, fig.width=6, fig.height=6, echo = TRUE, eval = TRUE, message = FALSE, warning = FALSE, fig.align = 'center')

Shiny

knitr::include_graphics("images/whatisshiny.png")

This is Shiny


What is Shiny?

knitr::include_graphics("images/shiny_definition.png")

What does that mean?

.pull-left3[

knitr::include_graphics("images/nohtml.png")

]

.pull-right3[

I can easily do this all in Shiny!

knitr::include_graphics("images/shiny_ss.png")

]

Histogram Example


Balloon Analogue Risk Task

Source: https://econpsychbasel.shinyapps.io/shinypsych_bart/


FFTrees Example

Source: https://econpsychbasel.shinyapps.io/shinyfftrees/

GlioVis

Source: http://gliovis.bioinfo.cnio.es/


Shiny

knitr::include_graphics("images/whatyoucando.png")

Shiny Tutorials

.pull-left3[

R Studio has great tutorials for creating Shiny Apps

knitr::include_graphics("images/learnshiny_B.png")

]

.pull-right3[

Learn by example. Tons of shiny apps online. Most code is available.

knitr::include_graphics("images/shinygallery.png")

]


How programming a Shiny App looks

knitr::include_graphics("images/shinyprogramming_ss.png")

Structure of a Shiny App

knitr::include_graphics("images/uiandserver.png")




# Let's explore the user interface of an app!

### P.S. You'll create this app in the practical!


User Interface

knitr::include_graphics("images/exampleapp_A.png")

User Interface

knitr::include_graphics("images/exampleapp_B.png")

User Interface

knitr::include_graphics("images/exampleapp_C.png")

User Interface

knitr::include_graphics("images/exampleapp_D.png")

User Interface

knitr::include_graphics("images/exampleapp_E.png")

User Interface

knitr::include_graphics("images/exampleapp_F.png")

User Interface

knitr::include_graphics("images/exampleapp_G.png")

User Interface

knitr::include_graphics("images/exampleapp_H.png")

User Interface

knitr::include_graphics("images/exampleapp_B.png")

The final app!


User Interface

The user interface typically contains two main components: Widgets and

knitr::include_graphics("images/userinterface_description.png")

User Interface, Widgets

knitr::include_graphics("images/widgetcode_output.png")

User Interface, Layout

knitr::include_graphics("images/shinylayouts.png")

Server

knitr::include_graphics("images/serverdescription.png")

Server

.pull-left3[

How does the server communicate with the user interface?



]

.pull-right3[

To send output to the user interface, you must use a render function

knitr::include_graphics("images/render_example.png")

]


Server

.pull-left3[

]

.pull-right3[

library(shiny)

# User Interface:
ui <- fluidPage(
  mainPanel(
    textInput("Title", "Title"),
    plotOutput("myplot")  # Create the plot output$displot
  )
)

server <- function(input, output) {

  # Define x
  x <- ChickWeight$weight

  # Send rendered plot to output
  output$myplot <- renderPlot({
    hist(x, main = input$Title)
  })
}

shinyApp(ui = ui, server = server)

]


Rendering output

The Shiny cheatsheet explains the most common functions for rendering and presenting output.

knitr::include_graphics("images/rendering_output.png")

Publishing (hosting) an app

.pull-left3[

- You can always run a Shiny app locally on your machine. - To get it online, you need to put it on a Shiny Server. - Publish an app (with some restrictions) at http://shinyapps.io from RStudio with one click! - Install a local server at your business (RStudio: $10,000 / year) - Other providers exist (e.g.; Amazon Web Services)

]

.pull-right3[

knitr::include_graphics("images/shinypublish.png")

]


Practical

knitr::include_graphics("images/exampleapp_A.png")

Questions?

.pull-left3[

knitr::include_graphics("images/exampleapp_A.png")

]

.pull-right3[

knitr::include_graphics("images/shinygallery.png")

]


Additional Slides


Server

.pull-left3[

]

.pull-right3[

What you want to write... (but it won't work)

library(shiny)

# User Interface: 
ui <- fluidPage(
    mainPanel(
      # Create a histogram of x in main panel
      hist(x)
    )
  )

server <- function(input, output) {

  # Define x
  x <- ChickWeight$weight

}

shinyApp(ui = ui, server = server)

]


Server

.pull-left3[

]

.pull-right3[

What you must write...this will work!

library(shiny)

# User Interface:
ui <- fluidPage(
  mainPanel(
    textInput("Title", "Title"),
    plotOutput("myplot")  # Create the plot output$displot
  )
)

server <- function(input, output) {

  # Define x
  x <- ChickWeight$weight

  # Send rendered plot to output
  output$myplot <- renderPlot({
    hist(x, main = input$Title)
  })
}

shinyApp(ui = ui, server = server)

]



therbootcamp/BaselRBootcamp2017 documentation built on May 3, 2019, 10:45 p.m.