4 min read

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

"学习笔记 系列导航

1 "学习笔记:Deep Learning in Python 学习笔记 2017-12-22
2 "学习笔记:Python 学习的流水笔记 2017-12-25
3 "学习笔记:Network Analysis in Python Part 1 学习笔记 2017-12-27
4 "学习笔记:XGBoost using Python 学习笔记 2017-12-28
5 "学习笔记:Supervised Learning with scikit-learn 学习笔记 2017-12-30
6 "学习笔记:Boosting理论部分 学习笔记 2018-01-02
7 "学习笔记:Machine Learning with the Experts School Budgets 学习笔记 2018-01-02
8 "学习笔记:犯罪心理解析 2018-01-02
9 "学习笔记:决策树理论部分 学习笔记 2018-01-03
10 "学习笔记:Shell 学习笔记 2018-01-04
11 "学习笔记:客户价值定价 学习笔记 2018-01-04
12 "学习笔记:Introduction to Git for Data Science 学习笔记 2018-01-06
13 "学习笔记:线性代数 整理笔记 2018-01-08
14 "学习笔记:退火算法 学习笔记 2018-01-09
15 "学习笔记:Fahrenheit 911 视频笔记 2018-01-18
16 "学习笔记:pandas debugging 学习笔记 2018-01-19
17 "学习笔记:brilliant.org概率论导论 学习笔记 2018-01-22
18 "学习笔记:Machine Learning with Tree-Based Models in R 学习笔记 2018-01-22
19 "学习笔记:Inference for Numerical Data 学习笔记 2018-01-26
20 "学习笔记:Support Vector Machines SVM 学习笔记 2018-01-26
21 "学习笔记:Introduction to DataCamp Projects 学习笔记 2018-01-28
22 "学习笔记:Working with Web Data in R 学习笔记 2018-01-28
23 "学习笔记:三种平均数使用的方式 学习笔记 2018-01-29
24 "学习笔记:戒律的复活 每周六更新 2018-01-29
25 "学习笔记:Communicating with Data in the Tidyverse 学习笔记 2018-01-31
26 "学习笔记:Kaggle R Tutorial on Machine Learning 学习笔记 2018-02-01
27 "学习笔记:Kaggle Python Tutorial on Machine Learning 学习笔记 2018-02-02
28 "学习笔记:圆桌派 第三季 视频笔记 2018-02-05
29 "学习笔记:基础与技巧整理 2018-02-25
30 "学习笔记:英语学习:积累:词汇、表达与语法整理 2018-04-09
31 "学习笔记:魏剑峰英语学习:笔记:表达与语法整理 2018-05-02
32 "学习笔记:Planet Money播客学习笔记:经济学话题解析 2018-06-05
33 "学习笔记:WSJ 学习笔记 2020-10-19

{r setup, include=FALSE} knitr::opts_chunk$set(eval = FALSE) * 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。

<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="330" height="86" src="//music.163.com/outchain/player?type=2&amp;id=28864476&amp;auto=1&amp;height=66">
</iframe>

好听!

<!-- ![](../../../picbackup/output.png) -->
<!-- -->
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 "学习笔记:Deep Learning in Python 学习笔记 2017-12-22
2 "学习笔记:Python 学习的流水笔记 2017-12-25
3 "学习笔记:Network Analysis in Python Part 1 学习笔记 2017-12-27
4 "学习笔记:XGBoost using Python 学习笔记 2017-12-28
5 "学习笔记:Supervised Learning with scikit-learn 学习笔记 2017-12-30
6 "学习笔记:Boosting理论部分 学习笔记 2018-01-02
7 "学习笔记:Machine Learning with the Experts School Budgets 学习笔记 2018-01-02
8 "学习笔记:犯罪心理解析 2018-01-02
9 "学习笔记:决策树理论部分 学习笔记 2018-01-03
10 "学习笔记:Shell 学习笔记 2018-01-04
11 "学习笔记:客户价值定价 学习笔记 2018-01-04
12 "学习笔记:Introduction to Git for Data Science 学习笔记 2018-01-06
13 "学习笔记:线性代数 整理笔记 2018-01-08
14 "学习笔记:退火算法 学习笔记 2018-01-09
15 "学习笔记:Fahrenheit 911 视频笔记 2018-01-18
16 "学习笔记:pandas debugging 学习笔记 2018-01-19
17 "学习笔记:brilliant.org概率论导论 学习笔记 2018-01-22
18 "学习笔记:Machine Learning with Tree-Based Models in R 学习笔记 2018-01-22
19 "学习笔记:Inference for Numerical Data 学习笔记 2018-01-26
20 "学习笔记:Support Vector Machines SVM 学习笔记 2018-01-26
21 "学习笔记:Introduction to DataCamp Projects 学习笔记 2018-01-28
22 "学习笔记:Working with Web Data in R 学习笔记 2018-01-28
23 "学习笔记:三种平均数使用的方式 学习笔记 2018-01-29
24 "学习笔记:戒律的复活 每周六更新 2018-01-29
25 "学习笔记:Communicating with Data in the Tidyverse 学习笔记 2018-01-31
26 "学习笔记:Kaggle R Tutorial on Machine Learning 学习笔记 2018-02-01
27 "学习笔记:Kaggle Python Tutorial on Machine Learning 学习笔记 2018-02-02
28 "学习笔记:圆桌派 第三季 视频笔记 2018-02-05
29 "学习笔记:基础与技巧整理 2018-02-25
30 "学习笔记:英语学习:积累:词汇、表达与语法整理 2018-04-09
31 "学习笔记:魏剑峰英语学习:笔记:表达与语法整理 2018-05-02
32 "学习笔记:Planet Money播客学习笔记:经济学话题解析 2018-06-05
33 "学习笔记:WSJ 学习笔记 2020-10-19