RShiny中的被动数据问题
我正在为一个个人项目制作一个闪亮的仪表盘,上面有一些足球数据。每当我更改要绘制的统计数据和/或过滤器时,我都会得到与第一个数据集中相同的玩家。例如,当我启动该应用程序时,该应用程序会创建一个学校历史上排名前十的冲刺者的图表,其中冲刺尝试次数的过滤器大于等于0。但是,当我将统计选择更改为“快速平均”时,显示的是这十名玩家,这是不正确的RShiny中的被动数据问题,r,shiny,R,Shiny,我正在为一个个人项目制作一个闪亮的仪表盘,上面有一些足球数据。每当我更改要绘制的统计数据和/或过滤器时,我都会得到与第一个数据集中相同的玩家。例如,当我启动该应用程序时,该应用程序会创建一个学校历史上排名前十的冲刺者的图表,其中冲刺尝试次数的过滤器大于等于0。但是,当我将统计选择更改为“快速平均”时,显示的是这十名玩家,这是不正确的 library(readxl) library(tidyverse) library(purrr) library(shiny) interface <-
library(readxl)
library(tidyverse)
library(purrr)
library(shiny)
interface <- fluidPage(
titlePanel(" "),
sidebarLayout(
sidebarPanel(
h1("Stats!"),
selectInput("stat_selection",
label = "Select a season statistics",
choices = c("Rushing Yards",
"Rushing Touchdowns",
"Rushing Average",
"Reciving Yards",
"Receptions",
"Receiving Touchdowns",
"Receiving Average"),
selected = "Rushing Yards"),
selectInput("filter_input",
label = "Select a statistic to filter by",
choices = c("Rushing Yards",
"Rushing Touchdowns",
"Rushing Average",
"Rushing Attempts",
"Reciving Yards",
"Receptions",
"Receiving Touchdowns",
"Receiving Average"),
selected = "Rushing Attempts"),
numericInput("filter_number",
label = "Type a number for the filter (>=)",
value = 0, min = 0),
actionButton("button", "Graph")),
mainPanel(
plotOutput("plot_button"),
tableOutput("table_button")
)
)
)
server_osu <- function(input, output) {
dataInput <- reactive({
switch(input$stat_selection,
"Rushing Yards" = rush_yds,
"Rushing Touchdowns" = rush_tds,
"Rushing Average" = rush_avg,
"Reciving Yards" = rec_yds,
"Receptions" = rec_rec,
"Receiving Touchdowns" = rec_td,
"Receiving Average" = rec_avg)
})
filterInput <- reactive({
switch(input$filter_input,
"Rushing Yards" = rush_yds,
"Rushing Touchdowns" = rush_tds,
"Rushing Average" = rush_avg,
"Rushing Attempts" = rush_att,
"Reciving Yards" = rec_yds,
"Receptions" = rec_rec,
"Receiving Touchdowns" = rec_td,
"Receiving Average" = rec_avg)
})
filter_number <- reactive(as.double(input$filter_number))
table_button_react <- eventReactive(input$button, {
dataset <- dataInput()
val <- filter_number()
colnames(dataset)[1] = "Player and Season"
dataset_filter <- filterInput()
colnames(dataset_filter)[1] = "Player and Season"
dataset <- left_join(dataset, dataset_filter)
colnames(dataset)[1] = "Player and Season"
og <- colnames(dataset)[3]
colnames(dataset)[3] = "filter"
original <- colnames(dataset)[2]
colnames(dataset)[2] = 'selected'
dataset <- dataset %>%
filter(filter >= val)
dataset <- dataset %>%
top_n(10) %>%
arrange(-selected)
colnames(dataset)[2] = original
colnames(dataset)[3] = og
dataset
})
plot_button_react <- eventReactive(input$button, {
dataset <- dataInput()
val <- filter_number()
colnames(dataset)[1] = "Player and Season"
dataset_filter <- filterInput()
colnames(dataset_filter)[1] = "Player and Season"
dataset <- left_join(dataset, dataset_filter)
colnames(dataset)[1] = "Player and Season"
colnames(dataset)[2] = "selected"
colnames(dataset)[3] = "filter"
dataset <- dataset %>%
filter(filter >= val)
top_ten <- dataset %>% top_n(10)
min = min(top_ten$selected)
max = max(top_ten$selected)
ggplot(top_ten, aes(x = reorder(`Player and Season`, -selected), y = selected)) +
geom_bar(stat = 'identity') + theme_minimal() + xlab('SEASON') +
ylab(input$stat_selection) + theme(text=element_text(size=16)) +
scale_fill_manual(values = c('#BBBBBB', '#BB0000')) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(legend.position = 'none') +
coord_cartesian(ylim=c(min - 0.05*min, max + 0.05*max)) +
theme(axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 10))) +
theme(axis.title.x = element_text(margin = margin(t = 10, r = 0, b = 10, l = 0))) +
theme(axis.text.y = element_text(size=14),
axis.title=element_text(size=16,face='bold')) +
labs(caption = '')
})
output$plot_button <- renderPlot({
plot_button_react()
})
output$table_button <- renderTable({
table_button_react()
})
}
库(readxl)
图书馆(tidyverse)
图书馆(purrr)
图书馆(闪亮)
界面正如我上面提到的,reprex(包括输入数据)将帮助我们帮助您。也就是说,我认为问题在于您的XXX\u按钮的反应
s仅依赖于input$button
。它们不依赖于输入$stat\u选择
,输入$filter\u编号
或输入$filter\u输入
。这就是为什么他们没有按照你的要求进行更新
修复很容易。只需将它们(在调用req()
的过程中,如果您愿意)添加到每个XXXX\u按钮的顶部,例如:
plot_button_react <- eventReactive(input$button, {
input$stat_selection
input$filter_number
input$filter_input
<your code here>
})
plot_button_react正如我前面提到的,reprex(包括输入数据)将帮助我们帮助您。也就是说,我认为问题在于您的XXX\u按钮的反应
s仅依赖于input$button
。它们不依赖于输入$stat\u选择
,输入$filter\u编号
或输入$filter\u输入
。这就是为什么他们没有按照你的要求进行更新
修复很容易。只需将它们(在调用req()
的过程中,如果您愿意)添加到每个XXXX\u按钮的顶部,例如:
plot_button_react <- eventReactive(input$button, {
input$stat_selection
input$filter_number
input$filter_input
<your code here>
})
plot\u按钮\u?哦,你是说“足球”!;)说真的,如果你在应用程序中加入一些输入数据并删除一些不相关的功能,那么帮助你会更容易。那会使你更容易得到帮助。有关如何制作简单的自包含示例或reprex.Football的建议,请参阅?哦,你是说“足球”!;)说真的,如果你在应用程序中加入一些输入数据并删除一些不相关的功能,那么帮助你会更容易。那会使你更容易得到帮助。有关如何制作简单的自包含示例或reprex的建议,请参阅。