r - 不返回 R 中的绘图和表格闪亮
问题描述
我正在做一个闪亮的项目,以获得 2019/2020 年英超联赛目标的仪表板。我已经抓取了我的数据并使用以下代码尝试制作一个漂亮的仪表板。问题是我的“情节”和“表格”没有在应用程序中返回。它只给出列而不是表格和绘图的内容。有人可以帮助我或看到我做错了什么?
library(httr)
library(tidyverse)
library(dplyr)
library(rvest)
library(ggplot2)
library(shiny)
library(shinythemes)
Top_goalscorers <- Top_goalscorers
dput(Top_goalscorers)
ui <- fluidPage(
titlePanel("Premier league goals 2019/2020"),
sidebarLayout(
sidebarPanel(
selectInput("typeInput", "Club",
choices = c("Arsenal", "Liverpool", "Chelsea", "Leicester City", "Southampton","Manchester City",
"Tottenham Hotspur", "Manchester United","Wolverhampton Wanderers","Chelsea","Burnley",
"Everton","Norwich City","Watford","West Ham United","Brighton & Hove Albion",
"Crystal Palace","Aston Villa","AFC Bournemouth","Sheffield United","Newcastle United"),
selected = "Arsenal"),
sliderInput("goalInput", "Goals", 0,30, c(0,30)),
radioButtons("spelerInput", "Speler",
choices = c("Jamie Vardy", "Harry Kane"),
selected = "Jamie Vardy")
),
mainPanel(
tabsetPanel(
tabPanel ("plot", plotOutput("myplot")),
tabPanel ("tabel", tableOutput("resultaten"))
)
)
)
)
server <- function(input, output) {
output$resultaten <- renderTable({
filtered <-
Top_goalscorers %>%
filter(club == input$typeInput,
goals >= input$goalInput,
speler == input$spelerInput)
filtered
})
output$myplot <- renderPlot({
filtered <-
Top_goalscorers %>%
filter(club == input$typeInput,
goals >= input$goalInput[1],
goals <= input$goalInput[2],
speler == input$spelerInput
)
ggplot(filtered, aes(x=goals, y=club, fill=goals_eerste_helft)) +
geom_point(size=2, shape=23)
})
}
shinyApp(ui = ui, server = server)
这里是数据集的结构:
解决方案
一次将过滤后的数据创建为反应对象,并在表格和绘图中使用它。尝试这个
server <- function(input, output, session) {
filtered <- reactive({
req(input$typeInput,input$goalInput[1],input$goalInput[2],input$spelerInput)
Top_goalscorers %>%
filter(club == input$typeInput,
goals >= input$goalInput[1],
goals <= input$goalInput[2],
speler == input$spelerInput
)})
output$resultaten <- renderTable({
filtered()
})
output$myplot <- renderPlot({
ggplot(filtered(), aes(x=goals, y=club, fill=goals_eerste_helft)) +
geom_point(size=2, shape=23)
})
}
推荐阅读
- reactjs - jsPDF addImage 输出灰色方块
- ofbiz - 使用 OFBIZ 中的图表从 Birt 报告生成 PDF
- ignite - 点燃瘦客户端 - 仅从扫描查询中获取键而不是值
- c# - 添加对何时为特定对象添加数据的限制
- docker - 无法访问 docker 容器 alpine 基础映像上的网页
- jobs - 在 Azure Databricks 环境中初始化集群需要更长的时间并且有时会引发错误
- solana - Solana 链上查询
- html - 仅单击一个子菜单时如何防止引导程序折叠所有子菜单?
- python - 如何根据列名合并数据框?
- azure-api-management - Azure APIM 部署失败。“代码”:“资源部署失败”