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')
knitr::include_graphics("images/whatisshiny.png")
knitr::include_graphics("images/shiny_definition.png")
.pull-left3[
Shiny allows you to easy create interactive websites to explore, analyse, and visualize data
No need to learn HTML, CSS, Javascript
knitr::include_graphics("images/nohtml.png")
]
.pull-right3[
knitr::include_graphics("images/shiny_ss.png")
Source: https://econpsychbasel.shinyapps.io/shinypsych_bart/
Source: http://gliovis.bioinfo.cnio.es/
knitr::include_graphics("images/whatyoucando.png")
.pull-left3[
knitr::include_graphics("images/learnshiny_B.png")
]
.pull-right3[
knitr::include_graphics("images/shinygallery.png")
]
knitr::include_graphics("images/shinyprogramming_ss.png")
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!
knitr::include_graphics("images/exampleapp_A.png")
knitr::include_graphics("images/exampleapp_B.png")
knitr::include_graphics("images/exampleapp_C.png")
knitr::include_graphics("images/exampleapp_D.png")
knitr::include_graphics("images/exampleapp_E.png")
knitr::include_graphics("images/exampleapp_F.png")
knitr::include_graphics("images/exampleapp_G.png")
knitr::include_graphics("images/exampleapp_H.png")
knitr::include_graphics("images/exampleapp_B.png")
The user interface typically contains two main components: Widgets and
knitr::include_graphics("images/userinterface_description.png")
knitr::include_graphics("images/widgetcode_output.png")
knitr::include_graphics("images/shinylayouts.png")
server()
function.knitr::include_graphics("images/serverdescription.png")
.pull-left3[
How does the server communicate with the user interface?
To present output (e.g.; a plot), it must be rendered in the server using a special rendering function renderXX()
,
Once it is rendered, it is sent to the output
and displayed in the user interface using an xxOutput()
function.
]
.pull-right3[
knitr::include_graphics("images/render_example.png")
]
.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)
]
The Shiny cheatsheet explains the most common functions for rendering and presenting output.
knitr::include_graphics("images/rendering_output.png")
.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")
]
knitr::include_graphics("images/exampleapp_A.png")
.pull-left3[
knitr::include_graphics("images/exampleapp_A.png")
]
.pull-right3[
knitr::include_graphics("images/shinygallery.png")
]
.pull-left3[
]
.pull-right3[
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)
]
.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)
]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.