-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_shiny.Rmd
45 lines (32 loc) · 2.28 KB
/
07_shiny.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
title: "Introduction to Shiny"
author: "Hao Zhu"
date: "2019-08-12 (updated `r Sys.Date()`)"
output:
html_document:
theme: cosmo
toc: true
toc_float:
collapsed: true
smooth_scroll: true
print: false
---
`Shiny` provides an easy to use web framework in R so that R users can start to create web apps. Before we get started, there are a few web-related concepts we need to clarify.
# Web 101
## Static web page v.s. Dynamic website
It may not be very obvious at the very begining but in most cases, websites can be categorized into 2 types: static & dynamic. Static websites are made of by many static web pages and are hosted by very simple web servers. The web server won't need to do any calculation, searching and database interaction. Their only job is to be the home for pre-generated web pages. The HTML webpages generated by R Markdown could be used in this case. Other examples include personal blog or project websites. The dynamic websites, however, do require the server to act as a big calculator behind the scene. Thinking about google, the webapp for your email, or anyother big site that you can do complex operations on them, as examples, you can easily find the differneces.
## HTML
HTML is the "language of the web". With a modern browser, on any webpage, you can right click and select "View Source". You will be able to see a lot of texts started with `<!DOCTYPE html>`. Basicaly, websites provide you access to these HTML files or contents, which are then rendered by your browser locally.
CSS controls the look and layout of HTML. It is another language which was created to separate things like color and fontsize from the main HTML language so that we could let HTML handle the content but use CSS to deal with the rest.
# Shiny
In the R world, you can easily generate a static HTML file using R Markdown but if you need to make a dynamic website that requires server-side calculation, you will have to use `shiny`.
Shiny split the task into 2 parts: UI and server. Here is a minimal example.
```{r, eval = F}
library(shiny)
ui <- fluidPage(
)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
```
For now, we did the rest part of this workshop in live teaching. A more detailed example will provided here in the future.