R shinydashboard + highcharter:参数未在 hc_add_series 中命名
R shinydashboard + highcharter: arguments are not named in hc_add_series
我正在尝试创建一个可以选择状态并根据该选择更新图表的仪表板,但我收到此错误:
'Warning: Error in : 'df', 'hcaes(x = date, y = injured)' arguments
are not named in hc_add_series [No stack trace available]'
library(tidyverse)
library(shiny)
library(shinydashboard)
library(highcharter)
ui <- dashboardPage(dashboardHeader(title = 'Test Dashboard'),
dashboardSidebar(),
dashboardBody(fluidPage(selectInput('select',
label = 'States',
choices = unique(opts),
selected = 'Alabama'),
box(title = "Stock",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
highchartOutput('plot')))))
server <- function(input,
output) {
output$plot <- renderHighchart({
df <- reactive({
df <- massShooting2018.order %>%
filter(state %in% input$select) %>%
group_by(date) %>%
summarise(
dead = sum(dead),
injured = (sum(injured)),
total = sum(total)
)
})
highchart(type = "stock") %>%
hc_chart("line",
name = "base",
hcaes(x = date)
) %>%
hc_add_series(df,
name = "Total",
type = "line",
hcaes(
x = date,
y = total
)
) %>%
hc_add_series(df,
name = "Dead",
type = "line",
hcaes(
x = date,
y = dead
)
) %>%
hc_add_series(df,
name = "Injured",
type = "line",
hcaes(
x = date,
y = injured
)
) %>%
hc_tooltip(
crosshairs = TRUE,
shared = TRUE,
borderWidth = 2,
table = TRUE
)
})
}
shinyApp(ui, server)
使用之前的数据集:
massShooting2018 <- read.csv('shootings_2018.csv')
massShooting2018.clean <- massShooting2018 %>%
clean_names() %>%
mutate(date = dmy(date))
massShooting2018.order <- massShooting2018.clean %>%
group_by(date, state) %>%
summarise(dead = sum(dead),
injured = sum(injured),
total = sum(total),
description, .groups = 'drop')
opts <- massShooting2018.order %>%
sample_frac(1) %>%
select(state) %>%
arrange(state)
非常感谢您的阅读,希望我能解决这个问题。
反应函数后df
的调用应该是df()
:
library(tidyverse)
library(shiny)
library(shinydashboard)
library(highcharter)
library(janitor)
library(lubridate)
massShooting2018 <- read.csv('shootings_2018.csv')
massShooting2018.clean <- massShooting2018 %>%
clean_names() %>%
mutate(date = dmy(date))
massShooting2018.order <- massShooting2018.clean %>%
group_by(date, state) %>%
summarise(dead = sum(dead),
injured = sum(injured),
total = sum(total),
description, .groups = 'drop')
opts <- massShooting2018.order %>%
sample_frac(1) %>%
select(state) %>%
arrange(state)
ui <- dashboardPage(dashboardHeader(title = 'Test Dashboard'),
dashboardSidebar(),
dashboardBody(fluidPage(selectInput('select',
label = 'States',
choices = unique(opts),
selected = 'Alabama'),
box(title = "Stock",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
highchartOutput('plot')))))
server <- function(input,
output)
{
output$plot <- renderHighchart({
df <- reactive({df <- massShooting2018.order %>%
filter(state %in% input$select) %>%
group_by(date) %>%
summarise(dead = sum(dead),
injured = (sum(injured)),
total = sum(total))})
highchart(type = 'stock') %>%
hc_chart('line',
name = 'base',
hcaes(x = date)) %>%
hc_add_series(df(),
name = 'Total',
type = 'line',
hcaes(x = date,
y = total)) %>%
hc_add_series(df(),
name = 'Dead',
type = 'line',
hcaes(x = date,
y = dead)) %>%
hc_add_series(df(),
name = 'Injured',
type = 'line',
hcaes(x = date,
y = injured)) %>%
hc_tooltip(crosshairs = TRUE,
shared = TRUE,
borderWidth = 2,
table = TRUE)})
}
shinyApp(ui, server)
我正在尝试创建一个可以选择状态并根据该选择更新图表的仪表板,但我收到此错误:
'Warning: Error in : 'df', 'hcaes(x = date, y = injured)' arguments are not named in hc_add_series [No stack trace available]'
library(tidyverse)
library(shiny)
library(shinydashboard)
library(highcharter)
ui <- dashboardPage(dashboardHeader(title = 'Test Dashboard'),
dashboardSidebar(),
dashboardBody(fluidPage(selectInput('select',
label = 'States',
choices = unique(opts),
selected = 'Alabama'),
box(title = "Stock",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
highchartOutput('plot')))))
server <- function(input,
output) {
output$plot <- renderHighchart({
df <- reactive({
df <- massShooting2018.order %>%
filter(state %in% input$select) %>%
group_by(date) %>%
summarise(
dead = sum(dead),
injured = (sum(injured)),
total = sum(total)
)
})
highchart(type = "stock") %>%
hc_chart("line",
name = "base",
hcaes(x = date)
) %>%
hc_add_series(df,
name = "Total",
type = "line",
hcaes(
x = date,
y = total
)
) %>%
hc_add_series(df,
name = "Dead",
type = "line",
hcaes(
x = date,
y = dead
)
) %>%
hc_add_series(df,
name = "Injured",
type = "line",
hcaes(
x = date,
y = injured
)
) %>%
hc_tooltip(
crosshairs = TRUE,
shared = TRUE,
borderWidth = 2,
table = TRUE
)
})
}
shinyApp(ui, server)
使用之前的数据集:
massShooting2018 <- read.csv('shootings_2018.csv')
massShooting2018.clean <- massShooting2018 %>%
clean_names() %>%
mutate(date = dmy(date))
massShooting2018.order <- massShooting2018.clean %>%
group_by(date, state) %>%
summarise(dead = sum(dead),
injured = sum(injured),
total = sum(total),
description, .groups = 'drop')
opts <- massShooting2018.order %>%
sample_frac(1) %>%
select(state) %>%
arrange(state)
非常感谢您的阅读,希望我能解决这个问题。
反应函数后df
的调用应该是df()
:
library(tidyverse)
library(shiny)
library(shinydashboard)
library(highcharter)
library(janitor)
library(lubridate)
massShooting2018 <- read.csv('shootings_2018.csv')
massShooting2018.clean <- massShooting2018 %>%
clean_names() %>%
mutate(date = dmy(date))
massShooting2018.order <- massShooting2018.clean %>%
group_by(date, state) %>%
summarise(dead = sum(dead),
injured = sum(injured),
total = sum(total),
description, .groups = 'drop')
opts <- massShooting2018.order %>%
sample_frac(1) %>%
select(state) %>%
arrange(state)
ui <- dashboardPage(dashboardHeader(title = 'Test Dashboard'),
dashboardSidebar(),
dashboardBody(fluidPage(selectInput('select',
label = 'States',
choices = unique(opts),
selected = 'Alabama'),
box(title = "Stock",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
highchartOutput('plot')))))
server <- function(input,
output)
{
output$plot <- renderHighchart({
df <- reactive({df <- massShooting2018.order %>%
filter(state %in% input$select) %>%
group_by(date) %>%
summarise(dead = sum(dead),
injured = (sum(injured)),
total = sum(total))})
highchart(type = 'stock') %>%
hc_chart('line',
name = 'base',
hcaes(x = date)) %>%
hc_add_series(df(),
name = 'Total',
type = 'line',
hcaes(x = date,
y = total)) %>%
hc_add_series(df(),
name = 'Dead',
type = 'line',
hcaes(x = date,
y = dead)) %>%
hc_add_series(df(),
name = 'Injured',
type = 'line',
hcaes(x = date,
y = injured)) %>%
hc_tooltip(crosshairs = TRUE,
shared = TRUE,
borderWidth = 2,
table = TRUE)})
}
shinyApp(ui, server)