4 min read

学习笔记:Building Web Applications in R with Shiny 学习笔记

学习笔记 系列导航

1 Hive/Impala 学习笔记 2017-12-04
2 KS 学习笔记 2017-12-06
3 datacamp pandas DataFrames 学习笔记 2017-12-11
4 datacamp pandas Merging DataFrames 学习笔记 2017-12-13
5 Databases in Python 学习笔记 2017-12-14
6 Data Visualization with Python 学习笔记 2017-12-16
7 Exploratory data analysis in Python 学习笔记 2017-12-17
8 Statistical Thinking in Python (Part-2) 学习笔记 2017-12-18
9 list comprehensions in Python 学习笔记 2017-12-19
10 无监督学习:Unsupervised Learning in Python 学习笔记 2017-12-20
11 学习笔记:Deep Learning in Python 学习笔记 2017-12-22
12 学习笔记:Python 学习的流水笔记 2017-12-25
13 学习笔记:Network Analysis in Python Part 1 学习笔记 2017-12-27
14 学习笔记:XGBoost using Python 学习笔记 2017-12-28
15 学习笔记:Supervised Learning with scikit-learn 学习笔记 2017-12-30
16 学习笔记:Boosting理论部分 学习笔记 2018-01-02
17 学习笔记:Machine Learning with the Experts School Budgets 学习笔记 2018-01-02
18 学习笔记:犯罪心理解析 2018-01-02
19 学习笔记:决策树理论部分 学习笔记 2018-01-03
20 学习笔记:Shell 学习笔记 2018-01-04
21 学习笔记:客户价值定价 学习笔记 2018-01-04
22 学习笔记:Introduction to Git for Data Science 学习笔记 2018-01-06
23 学习笔记:线性代数 整理笔记 2018-01-08
24 学习笔记:退火算法 学习笔记 2018-01-09
25 学习笔记:Fahrenheit 911 视频笔记 2018-01-18
26 学习笔记:pandas debugging 学习笔记 2018-01-19
27 学习笔记:brilliant.org概率论导论 学习笔记 2018-01-22
28 学习笔记:Machine Learning with Tree-Based Models in R 学习笔记 2018-01-22
29 学习笔记:Inference for Numerical Data 学习笔记 2018-01-26
30 学习笔记:Support Vector Machines SVM 学习笔记 2018-01-26
31 学习笔记:Introduction to DataCamp Projects 学习笔记 2018-01-28
32 学习笔记:Working with Web Data in R 学习笔记 2018-01-28
33 学习笔记:三种平均数使用的方式 学习笔记 2018-01-29
34 学习笔记:戒律的复活 每周六更新 2018-01-29
35 学习笔记:Communicating with Data in the Tidyverse 学习笔记 2018-01-31
36 学习笔记:Kaggle R Tutorial on Machine Learning 学习笔记 2018-02-01
37 学习笔记:Kaggle Python Tutorial on Machine Learning 学习笔记 2018-02-02
38 技术:ggridges 山峦图 学习笔记 2018-02-02
39 技术:XGBoost 学习笔记 2018-02-02
40 学习笔记:圆桌派 第三季 视频笔记 2018-02-05
41 学习笔记:基础与技巧整理 2018-02-25
42 集成学习R SuperLearner包学习笔记 2018-03-04
43 学习笔记:英语学习积累:词汇、表达与语法整理 2018-04-09
44 技术:原理与应用学习笔记 2018-04-29
45 学习笔记:魏剑峰英语学习笔记:表达与语法整理 2018-05-02
46 技术:方法与实践学习笔记 2018-05-12
47 无监督学习:主成分分析(PCA)原理与实现学习笔记 2018-05-17
48 技术:特征筛选学习笔记 2018-05-29
49 学习笔记:Planet Money播客学习笔记:经济学话题解析 2018-06-05
50 基础算法系列梯度下降算法详解:原理与优化学习笔记 2018-07-11
51 技术:统计建模学习笔记 2018-07-24
52 技术:指标设计学习笔记 2018-09-20
53 技术:安装与使用基础学习笔记 2018-11-07
54 📈 ggplot 设计思路 学习笔记 2019-12-26
55 🧩 Python 函数编写学习笔记 2019-12-31
56 技术:特征工程之目标编码学习笔记 2020-01-20
57 📚 词向量 学习笔记 2020-07-04
58 主题模型:学习笔记 2020-07-04
59 学习笔记:WSJ 学习笔记 2020-10-19
60 健身:学习笔记 2025-08-19
  • Building Web Applications in R with Shiny 做app,需求也很强,必须搞啊! 这些东西就是入门慢。

  • 4 hours

  • 17 Videos

  • 55 Exercises

  • 1,129 Participants 说明了问题,学习的人很少。

Mine Cetinkaya-Rundel | DataCamp 她教的, 她有很多课。

selected是default值设计。

library(shiny)
library(ggplot2)
load(url("http://s3.amazonaws.com/assets.datacamp.com/production/course_4850/datasets/movies.Rdata"))

# Define UI for application that plots features of movies 
ui <- fluidPage(
  
  # Sidebar layout with a input and output definitions 
  sidebarLayout(
    
    # Inputs
    sidebarPanel(
      
      # Select variable for y-axis
      selectInput(inputId = "y", 
                  label = "Y-axis:",
                  choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), 
                  selected = "imdb_rating"),
      # Select variable for x-axis
      selectInput(inputId = "x", 
                  label = "X-axis:",
                  choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), 
                  selected = "imdb_num_votes")
    ),
    
    # Outputs
    mainPanel(
      plotOutput(outputId = "scatterplot")
    )
  )
)

# Define server function required to create the scatterplot
server <- function(input, output) {

  # Create scatterplot object the plotOutput function is expecting
  output$scatterplot <- renderPlot({
    ggplot(data = movies, aes_string(x = input$x, y = input$y)) +
      geom_point()
  })
}

# Create a Shiny app object
shinyApp(ui = ui, server = server)

selectInput就是input框的选择框。 其中, inputId是用于画图的识别id。 新增一个selectInput

library(shiny)
library(ggplot2)
load(url("http://s3.amazonaws.com/assets.datacamp.com/production/course_4850/datasets/movies.Rdata"))

# Define UI for application that plots features of movies
ui <- fluidPage(
  
  # Sidebar layout with a input and output definitions
  sidebarLayout(
    
    # Inputs
    sidebarPanel(
      
      # Select variable for y-axis
      selectInput(inputId = "y", 
                  label = "Y-axis:",
                  choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), 
                  selected = "audience_score"),
      
      # Select variable for x-axis
      selectInput(inputId = "x", 
                  label = "X-axis:",
                  choices = c("imdb_rating", "imdb_num_votes", "critics_score", "audience_score", "runtime"), 
                  selected = "critics_score"),
      
      # Select variable for color
      selectInput(inputId = "z", 
                  label = "Color by:",
                  choices = c("title_type", "genre", "mpaa_rating", "critics_rating", "audience_rating"),
                  selected = "mpaa_rating")
    ),
    
    # Outputs
    mainPanel(
      plotOutput(outputId = "scatterplot")
    )
  )
)

# Define server function required to create the scatterplot
server <- function(input, output) {
  
  # Create the scatterplot object the plotOutput function is expecting
  output$scatterplot <- renderPlot({
    ggplot(data = movies, aes_string(x = input$x, y = input$y,
                                     color = input$z)) +
      geom_point()
  })
}

# Create a Shiny app object
shinyApp(ui = ui, server = server)

choices中, 修改label名字,很重要,因为有时候体现的时候,要展示中文。

library(shiny)
library(ggplot2)
load(url("http://s3.amazonaws.com/assets.datacamp.com/production/course_4850/datasets/movies.Rdata"))

# Define UI for application that plots features of movies
ui <- fluidPage(
  
  # Sidebar layout with a input and output definitions
  sidebarLayout(
    
    # Inputs
    sidebarPanel(
      
      # Select variable for y-axis
      selectInput(inputId = "y", 
                  label = "Y-axis:",
                  choices = c("IMDB rating" = "imdb_rating", 
                              "IMDB number of votes" = "imdb_num_votes", 
                              "Critics score" = "critics_score", 
                              "Audience score" = "audience_score", 
                              "Runtime" = "runtime"), 
                  selected = "audience_score"),
      
      # Select variable for x-axis
      selectInput(inputId = "x", 
                  label = "X-axis:",
                  choices = c("IMDB rating" = "imdb_rating", 
                              "IMDB number of votes" = "imdb_num_votes", 
                              "Critics score" = "critics_score", 
                              "Audience score" = "audience_score", 
                              "Runtime" = "runtime"), 
                  selected = "critics_score"),
      
      # Select variable for color
      selectInput(inputId = "z",
                  label = "Color by:",
                  choice = c("Title type" = "title_type",
                             "Genre" = "genre",
                             "MPAA rating" = "mpaa_rating",
                             "Critics rating" = "critics_rating",
                             "Audience rating" = "audience_rating"),
                  selected = "mpaa_rating"
                  )
    ),
    
    # Output
    mainPanel(
      plotOutput(outputId = "scatterplot")
    )
  )
)

# Define server function required to create the scatterplot
server <- function(input, output) {
  
  # Create the scatterplot object the plotOutput function is expecting
  output$scatterplot <- renderPlot({
    ggplot(data = movies, aes_string(x = input$x, y = input$y,
                                     color = input$z)) +
      geom_point()
  })
}

# Create a Shiny app object
shinyApp(ui = ui, server = server)

我个人感觉, 前面fluidPage就是导入导出数据的, server是具体实现的function。

好听!

library(shiny)
library(ggplot2)
load(url("http://s3.amazonaws.com/assets.datacamp.com/production/course_4850/datasets/movies.Rdata"))

# Define UI for application that plots features of movies
ui <- fluidPage(
  
  # Sidebar layout with a input and output definitions
  sidebarLayout(
    
    # Inputs
    sidebarPanel(
      
      # Select variable for y-axis
      selectInput(inputId = "y", 
                  label = "Y-axis:",
                  choices = c("IMDB rating"          = "imdb_rating", 
                              "IMDB number of votes" = "imdb_num_votes", 
                              "Critics score"        = "critics_score", 
                              "Audience score"       = "audience_score", 
                              "Runtime"              = "runtime"), 
                  selected = "audience_score"),
      
      # Select variable for x-axis
      selectInput(inputId = "x", 
                  label = "X-axis:",
                  choices = c("IMDB rating"          = "imdb_rating", 
                              "IMDB number of votes" = "imdb_num_votes", 
                              "Critics score"        = "critics_score", 
                              "Audience score"       = "audience_score", 
                              "Runtime"              = "runtime"), 
                  selected = "critics_score"),
      
      # Select variable for color
      selectInput(inputId = "z", 
                  label = "Color by:",
                  choices = c("Title type" = "title_type", 
                              "Genre" = "genre", 
                              "MPAA rating" = "mpaa_rating", 
                              "Critics rating" = "critics_rating", 
                              "Audience rating" = "audience_rating"),
                  selected = "mpaa_rating")
    ),
    
    # Outputs
    mainPanel(
      plotOutput(outputId = "scatterplot")
    )
  )
)

# Define server function required to create the scatterplot
server <- function(input, output) {
  
  # Create the scatterplot object the plotOutput function is expecting
  output$scatterplot <- renderPlot({
    ggplot(data = movies, aes_string(x = input$x, y = input$y,
                                     color = input$z)) +
      geom_point()
  })
}

# Create a Shiny app object
shinyApp(ui = ui, server = server)

书签。

学习笔记 系列导航

1 Hive/Impala 学习笔记 2017-12-04
2 KS 学习笔记 2017-12-06
3 datacamp pandas DataFrames 学习笔记 2017-12-11
4 datacamp pandas Merging DataFrames 学习笔记 2017-12-13
5 Databases in Python 学习笔记 2017-12-14
6 Data Visualization with Python 学习笔记 2017-12-16
7 Exploratory data analysis in Python 学习笔记 2017-12-17
8 Statistical Thinking in Python (Part-2) 学习笔记 2017-12-18
9 list comprehensions in Python 学习笔记 2017-12-19
10 无监督学习:Unsupervised Learning in Python 学习笔记 2017-12-20
11 学习笔记:Deep Learning in Python 学习笔记 2017-12-22
12 学习笔记:Python 学习的流水笔记 2017-12-25
13 学习笔记:Network Analysis in Python Part 1 学习笔记 2017-12-27
14 学习笔记:XGBoost using Python 学习笔记 2017-12-28
15 学习笔记:Supervised Learning with scikit-learn 学习笔记 2017-12-30
16 学习笔记:Boosting理论部分 学习笔记 2018-01-02
17 学习笔记:Machine Learning with the Experts School Budgets 学习笔记 2018-01-02
18 学习笔记:犯罪心理解析 2018-01-02
19 学习笔记:决策树理论部分 学习笔记 2018-01-03
20 学习笔记:Shell 学习笔记 2018-01-04
21 学习笔记:客户价值定价 学习笔记 2018-01-04
22 学习笔记:Introduction to Git for Data Science 学习笔记 2018-01-06
23 学习笔记:线性代数 整理笔记 2018-01-08
24 学习笔记:退火算法 学习笔记 2018-01-09
25 学习笔记:Fahrenheit 911 视频笔记 2018-01-18
26 学习笔记:pandas debugging 学习笔记 2018-01-19
27 学习笔记:brilliant.org概率论导论 学习笔记 2018-01-22
28 学习笔记:Machine Learning with Tree-Based Models in R 学习笔记 2018-01-22
29 学习笔记:Inference for Numerical Data 学习笔记 2018-01-26
30 学习笔记:Support Vector Machines SVM 学习笔记 2018-01-26
31 学习笔记:Introduction to DataCamp Projects 学习笔记 2018-01-28
32 学习笔记:Working with Web Data in R 学习笔记 2018-01-28
33 学习笔记:三种平均数使用的方式 学习笔记 2018-01-29
34 学习笔记:戒律的复活 每周六更新 2018-01-29
35 学习笔记:Communicating with Data in the Tidyverse 学习笔记 2018-01-31
36 学习笔记:Kaggle R Tutorial on Machine Learning 学习笔记 2018-02-01
37 学习笔记:Kaggle Python Tutorial on Machine Learning 学习笔记 2018-02-02
38 技术:ggridges 山峦图 学习笔记 2018-02-02
39 技术:XGBoost 学习笔记 2018-02-02
40 学习笔记:圆桌派 第三季 视频笔记 2018-02-05
41 学习笔记:基础与技巧整理 2018-02-25
42 集成学习R SuperLearner包学习笔记 2018-03-04
43 学习笔记:英语学习积累:词汇、表达与语法整理 2018-04-09
44 技术:原理与应用学习笔记 2018-04-29
45 学习笔记:魏剑峰英语学习笔记:表达与语法整理 2018-05-02
46 技术:方法与实践学习笔记 2018-05-12
47 无监督学习:主成分分析(PCA)原理与实现学习笔记 2018-05-17
48 技术:特征筛选学习笔记 2018-05-29
49 学习笔记:Planet Money播客学习笔记:经济学话题解析 2018-06-05
50 基础算法系列梯度下降算法详解:原理与优化学习笔记 2018-07-11
51 技术:统计建模学习笔记 2018-07-24
52 技术:指标设计学习笔记 2018-09-20
53 技术:安装与使用基础学习笔记 2018-11-07
54 📈 ggplot 设计思路 学习笔记 2019-12-26
55 🧩 Python 函数编写学习笔记 2019-12-31
56 技术:特征工程之目标编码学习笔记 2020-01-20
57 📚 词向量 学习笔记 2020-07-04
58 主题模型:学习笔记 2020-07-04
59 学习笔记:WSJ 学习笔记 2020-10-19
60 健身:学习笔记 2025-08-19