R ggplot不会对选择性输入作出反应
我正在尝试创建一个NBA投篮分析仪表板,我创建了5个变量,根据我从下载的所有NBA球队的数据框中存在的数据,按照更新对数据进行排序。因此,要在您的机器上复制此文件,您只需下载一个csv文件 这是通过selectizeGroupUI和SelectiveGroupServer完成的 我的问题是,当用户选择约束来子集数据时,我想从用户通过输入创建的特定子集中提取两列 这样,最终的仪表板将完全基于用户输入的内容显示ggplot中的x和y坐标,我知道如何将其编码到ggplot函数本身中 任何帮助都将不胜感激R ggplot不会对选择性输入作出反应,r,ggplot2,shiny,R,Ggplot2,Shiny,我正在尝试创建一个NBA投篮分析仪表板,我创建了5个变量,根据我从下载的所有NBA球队的数据框中存在的数据,按照更新对数据进行排序。因此,要在您的机器上复制此文件,您只需下载一个csv文件 这是通过selectizeGroupUI和SelectiveGroupServer完成的 我的问题是,当用户选择约束来子集数据时,我想从用户通过输入创建的特定子集中提取两列 这样,最终的仪表板将完全基于用户输入的内容显示ggplot中的x和y坐标,我知道如何将其编码到ggplot函数本身中 任何帮助都将不胜感
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(shinythemes)
library(plotly)
library(tidyverse)
library(rsconnect)
library(readr)
library(ggplot2)
library(plyr)
library(dplyr)
library(jpeg)
library(grid)
library(RCurl)
library(shinyWidgets)
# import all NBA teams csv files into one dataframe
mydir = "NBA Teams 2017-2018"
myfiles = list.files(path = mydir, pattern = "*.csv", full.names = TRUE)
myfiles
data_csv = ldply(myfiles, read_csv)
courtImg <- "http://robslink.com/SAS/democd54/nba_court_dimensions.jpg"
court <- rasterGrob(readJPEG(getURLContent(courtImg)),
width = unit(1, "npc"), height = unit(1, "npc"))
ui = pageWithSidebar(
headerPanel("NBA 2017-2018 Season: Shooting Analysis"),
sidebarPanel(
# uiOutput("team_name"),
# uiOutput("name"),
# uiOutput("shot_type"),
# uiOutput("shot_made_flag"),
# uiOutput("action_type")
selectizeGroupUI(
id = "my-filters",
inline = FALSE,
params = list(
team_name = list(inputId = "team_name", title = "NBA Team", placeholder = 'Select NBA Team'),
name = list(inputId = "name", title = "Player", placeholder = 'Select a Player'),
shot_type = list(inputId = "shot_type", title = "2 PT or 3 PT", placeholder = 'Select Value'),
shot_made_flag = list(inputId = "shot_made_flag", title = "FGA / FG", placeholder = 'Select Between All Shot Attempts or Only Shots Made'),
action_type = list(inputId = "action_type", title = "Shot Type", placeholder = 'Select Shot Type'))
)
),
mainPanel(
#tableOutput("table"),
plotOutput("court_plot")
)
)
server <- function(input, output, session) {
res_mod <- callModule(
module = selectizeGroupServer,
id = "my-filters",
data = data_csv,
vars = c("team_name", "name", "shot_type", "shot_made_flag", "action_type")
)
output$court_plot <- renderPlot({
res_mod()
ggplot(data_csv, aes(x = x, y = colory)) +
annotation_custom(court, -250, 250, -50, 420) +
geom_point(color = data_csv$shot_type) +
xlim(-250, 250) +
ylim(-50, 420)
})
}
shinyApp(ui = ui, server = server)
#
#这是一个闪亮的web应用程序。您可以通过单击来运行应用程序
#上面的“运行应用程序”按钮。
#
#在此处了解有关使用Shining构建应用程序的更多信息:
#
# http://shiny.rstudio.com/
#
图书馆(闪亮)
图书馆(shinythemes)
图书馆(绘本)
图书馆(tidyverse)
图书馆(rsconnect)
图书馆(readr)
图书馆(GG2)
图书馆(plyr)
图书馆(dplyr)
图书馆(jpeg)
图书馆(网格)
图书馆(RCurl)
图书馆(shinyWidgets)
#将所有NBA球队csv文件导入到一个数据帧中
mydir=“NBA球队2017-2018”
myfiles=list.files(path=mydir,pattern=“*.csv”,full.names=TRUE)
我的文件
数据\u csv=ldply(我的文件,读取\u csv)
courtImg以下是更正代码:
我将data\u I=res\u mod()
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(shinythemes)
library(plotly)
library(tidyverse)
library(rsconnect)
library(readr)
library(ggplot2)
library(plyr)
library(dplyr)
library(jpeg)
library(grid)
library(RCurl)
library(shinyWidgets)
# import all NBA teams csv files into one dataframe
mydir = "NBA Teams 2017-2018"
myfiles = list.files(path = mydir, pattern = "*.csv", full.names = TRUE)
myfiles
# declare csv file
data_csv = ldply(myfiles, read_csv)
# upload image of court for ggplot
courtImg <- "http://robslink.com/SAS/democd54/nba_court_dimensions.jpg"
court <- rasterGrob(readJPEG(getURLContent(courtImg)),
width = unit(1, "npc"), height = unit(1, "npc"))
# ui for shiny dashboard
ui = fluidPage(
# change the theme to be easier on the eyes
theme = shinytheme('darkly'),
# title of shiny app
headerPanel("NBA 2017-2018 Season: Shooting Analysis"),
sidebarPanel(
# create a subset of the data that changes based on user input and narrows down the choices
selectizeGroupUI(
id = "my-filters",
inline = FALSE,
params = list(
team_name = list(inputId = "team_name", title = "NBA Team", placeholder = 'Select NBA Team'),
name = list(inputId = "name", title = "Player", placeholder = 'Select a Player'),
shot_type = list(inputId = "shot_type", title = "2 PT or 3 PT", placeholder = 'Select Value'),
shot_made_flag = list(inputId = "shot_made_flag", title = "Missed(0) or Made(1) Shot", placeholder = 'Select Between All Shot Attempts or Only Shots Made'),
action_type = list(inputId = "action_type", title = "Shot Type", placeholder = 'Select Shot Type'))
),
status = "primary"
),
mainPanel(
# plot the court next to the user input
plotOutput(outputId = "court_plot", width = '800px')
)
)
# server side of the app that allows the user interactions to affect the dataframe
server <- function(input, output, session) {
# allow the custom subset dataframe to be called
res_mod <- callModule(
module = selectizeGroupServer,
id = "my-filters",
data = data_csv,
vars = c("team_name", "name", "shot_type", "shot_made_flag", "action_type")
)
# the code side of the plot that plots the users input by calling the subsetted dataframe
output$court_plot <- renderPlot({
data_i = res_mod()
data_i %>% ggplot(aes(x, y)) +
annotation_custom(court, -250, 250, -50, 420) +
geom_point(color = data_i$shot_type) +
xlim(-250, 250) +
ylim(-50, 420)
})
}
shinyApp(ui = ui, server = server)
#
#这是一个闪亮的web应用程序。您可以通过单击来运行应用程序
#上面的“运行应用程序”按钮。
#
#在此处了解有关使用Shining构建应用程序的更多信息:
#
# http://shiny.rstudio.com/
#
图书馆(闪亮)
图书馆(shinythemes)
图书馆(绘本)
图书馆(tidyverse)
图书馆(rsconnect)
图书馆(readr)
图书馆(GG2)
图书馆(plyr)
图书馆(dplyr)
图书馆(jpeg)
图书馆(网格)
图书馆(RCurl)
图书馆(shinyWidgets)
#将所有NBA球队csv文件导入到一个数据帧中
mydir=“NBA球队2017-2018”
myfiles=list.files(path=mydir,pattern=“*.csv”,full.names=TRUE)
我的文件
#声明csv文件
数据\u csv=ldply(我的文件,读取\u csv)
#上传法庭的图像以供参考
courtImg以下是更正代码:
我将data\u I=res\u mod()
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(shinythemes)
library(plotly)
library(tidyverse)
library(rsconnect)
library(readr)
library(ggplot2)
library(plyr)
library(dplyr)
library(jpeg)
library(grid)
library(RCurl)
library(shinyWidgets)
# import all NBA teams csv files into one dataframe
mydir = "NBA Teams 2017-2018"
myfiles = list.files(path = mydir, pattern = "*.csv", full.names = TRUE)
myfiles
# declare csv file
data_csv = ldply(myfiles, read_csv)
# upload image of court for ggplot
courtImg <- "http://robslink.com/SAS/democd54/nba_court_dimensions.jpg"
court <- rasterGrob(readJPEG(getURLContent(courtImg)),
width = unit(1, "npc"), height = unit(1, "npc"))
# ui for shiny dashboard
ui = fluidPage(
# change the theme to be easier on the eyes
theme = shinytheme('darkly'),
# title of shiny app
headerPanel("NBA 2017-2018 Season: Shooting Analysis"),
sidebarPanel(
# create a subset of the data that changes based on user input and narrows down the choices
selectizeGroupUI(
id = "my-filters",
inline = FALSE,
params = list(
team_name = list(inputId = "team_name", title = "NBA Team", placeholder = 'Select NBA Team'),
name = list(inputId = "name", title = "Player", placeholder = 'Select a Player'),
shot_type = list(inputId = "shot_type", title = "2 PT or 3 PT", placeholder = 'Select Value'),
shot_made_flag = list(inputId = "shot_made_flag", title = "Missed(0) or Made(1) Shot", placeholder = 'Select Between All Shot Attempts or Only Shots Made'),
action_type = list(inputId = "action_type", title = "Shot Type", placeholder = 'Select Shot Type'))
),
status = "primary"
),
mainPanel(
# plot the court next to the user input
plotOutput(outputId = "court_plot", width = '800px')
)
)
# server side of the app that allows the user interactions to affect the dataframe
server <- function(input, output, session) {
# allow the custom subset dataframe to be called
res_mod <- callModule(
module = selectizeGroupServer,
id = "my-filters",
data = data_csv,
vars = c("team_name", "name", "shot_type", "shot_made_flag", "action_type")
)
# the code side of the plot that plots the users input by calling the subsetted dataframe
output$court_plot <- renderPlot({
data_i = res_mod()
data_i %>% ggplot(aes(x, y)) +
annotation_custom(court, -250, 250, -50, 420) +
geom_point(color = data_i$shot_type) +
xlim(-250, 250) +
ylim(-50, 420)
})
}
shinyApp(ui = ui, server = server)
#
#这是一个闪亮的web应用程序。您可以通过单击来运行应用程序
#上面的“运行应用程序”按钮。
#
#在此处了解有关使用Shining构建应用程序的更多信息:
#
# http://shiny.rstudio.com/
#
图书馆(闪亮)
图书馆(shinythemes)
图书馆(绘本)
图书馆(tidyverse)
图书馆(rsconnect)
图书馆(readr)
图书馆(GG2)
图书馆(plyr)
图书馆(dplyr)
图书馆(jpeg)
图书馆(网格)
图书馆(RCurl)
图书馆(shinyWidgets)
#将所有NBA球队csv文件导入到一个数据帧中
mydir=“NBA球队2017-2018”
myfiles=list.files(path=mydir,pattern=“*.csv”,full.names=TRUE)
我的文件
#声明csv文件
数据\u csv=ldply(我的文件,读取\u csv)
#上传法庭的图像以供参考
courtImg可能ggplot2(res_mod(),…)
而不是在静态对象data_csv
上调用它?(res_mod()
为您提供了对帧的动态查看,但我不相信它正在改变底层对象。)@r2evans我尝试过,但我在主面板上得到了“错误:参数“id”丢失,没有默认值”,应该显示ggplot。在resu mod()之前添加browser()
)
以便查看res\u mod()
的外观,确保其有意义;并在本地运行此操作(未部署到RSC或其他…由rsconnect
的不必要加载推断)。另一点:您在geom_点中使用的数据\u csv$shot_type
不正确;我怀疑它应该是geom_point(aes(shot_type))
。也许ggplot2(res_mod(),…)
而不是在静态对象上调用它data_csv
?(res_mod()
为您提供了对帧的动态查看,但我不相信它正在改变底层对象。)@r2evans我尝试过,但我在主面板上得到了“错误:参数“id”丢失,没有默认值”,应该显示ggplot。在resu mod()之前添加browser()
)
以便查看res\u mod()
的外观,确保其有意义;并在本地运行此操作(未部署到RSC或其他…由rsconnect
的不必要加载推断)。另一点:您在geom_点中使用的数据\u csv$shot_type
不正确;我怀疑应该是geom_point(aes(shot_type))
。