r - 加载 ggplot2 后,Highcharter 绘图失败
问题描述
在我闪亮的应用程序中,我想创建一个线图,其中的group
值基于选定的用户输入:input$tt_groupvar
. Highcharter 可以使用 来做到这一点hcaes_string
,但是我在现实生活中的应用程序加载了 ggplot2,并且hchart
失败了。
在下面的 app1 中,ggplot2 未显式加载,并且该图正确地将数据分组基于input$tt_groupvar
. 但在下面的 app2 中,唯一的区别是 ggplot2 已加载,应用程序失败。通过 app2 加载 ggplot2 后,app1 不再正常工作。
我知道我可以使用 ggplot2 或 plotly 使这项工作正常工作,但我真的很想使用 highcharter。有没有办法解决这个问题?
任何见解都非常感谢!
应用程序1
library(shiny)
library(dplyr)
library(highcharter)
df <- data.frame(floorDate = as.Date(c("01/01/2017", "01/01/2017", "01/01/2017", "01/01/2018", "01/01/2018", "01/01/2018", "01/01/2019", "01/01/2019", "01/01/2019", "06/01/2017", "11/01/2018", "12/01/2019"), format = "%m/%d/%Y"),
location = c("MWH", "MWH", "MWH", "MWH", "SH", "MWH","MWH","MWH", "SH", "SH", "MIF", "MIF"),
ethnicity = c("W", "W", "B", "B", "MULT", "MULT","MULT","W","W","B","MULT","B"))
ui <- fluidPage(
titlePanel("my title"),
sidebarLayout(
sidebarPanel(
helpText("Select a grouping variable to plot the number of ROCs
by the values in that group across January 2017 to January 2020."),
selectizeInput("tt_groupvar",
label = "Choose a grouping variable:",
choices = c("Location"="location", "Ethnicity"="ethnicity"),
multiple = FALSE,
selected = c("location"))
),
mainPanel(
highchartOutput("timeTrend_1")
)
)
)
server <- function(input, output) {
output$timeTrend_1 <- renderHighchart({
hchart(df %>%
group_by_at(c("floorDate", input$tt_groupvar)) %>%
count(),
type = "line",
hcaes_string(x = "floorDate", y = "n", group = input$tt_groupvar)) %>% #THE ISSUE IS HERE!!!!
hc_xAxis(title = list(text = "")) %>%
hc_yAxis(title = list(text = "# of ROCs")) %>%
hc_title(text = "Number of ROCs per Month by Group from 2017 to January 2019")
})
}
shinyApp(ui, server)
应用程序2
library(shiny)
library(dplyr)
library(highcharter)
library(ggplot2)
df <- data.frame(floorDate = as.Date(c("01/01/2017", "01/01/2017", "01/01/2017", "01/01/2018", "01/01/2018", "01/01/2018", "01/01/2019", "01/01/2019", "01/01/2019", "06/01/2017", "11/01/2018", "12/01/2019"), format = "%m/%d/%Y"),
location = c("MWH", "MWH", "MWH", "MWH", "SH", "MWH","MWH","MWH", "SH", "SH", "MIF", "MIF"),
ethnicity = c("W", "W", "B", "B", "MULT", "MULT","MULT","W","W","B","MULT","B"))
ui <- fluidPage(
titlePanel("my title"),
sidebarLayout(
sidebarPanel(
helpText("Select a grouping variable to plot the number of ROCs
by the values in that group across January 2017 to January 2020."),
selectizeInput("tt_groupvar",
label = "Choose a grouping variable:",
choices = c("Location"="location", "Ethnicity"="ethnicity"),
multiple = FALSE,
selected = c("location"))
),
mainPanel(
highchartOutput("timeTrend_1")
)
)
)
server <- function(input, output) {
output$timeTrend_1 <- renderHighchart({
hchart(df %>%
group_by_at(c("floorDate", input$tt_groupvar)) %>%
count(),
type = "line",
hcaes_string(x = "floorDate", y = "n", group = input$tt_groupvar)) %>% # THE ISSUE IS HERE!
hc_xAxis(title = list(text = "")) %>%
hc_yAxis(title = list(text = "# of ROCs")) %>%
hc_title(text = "Number of ROCs per Month by Group from 2017 to January 2019")
})
}
shinyApp(ui, server)
解决方案
推荐阅读
- python - Python RandomForest 将 rfe.support_ 转换为列表
- python - Python中的纸浆没有找到最大值
- php - 如何在php中从F-00001开始生成唯一的tag_id
- java - 在 Spring 4 JPA Hibernate 5 中使用 @NamedStoredProcedureQuery 上的过程模式
- python-3.x - 通过穿透一个while循环来停止动作
- feathersjs - 如何使用过滤器从内部服务回调?
- postgresql - 为什么在 jps 中使用 postgres9 时 Jelastic 环境不起作用?
- android - 添加 firebase 依赖项会导致 gradle 同步失败
- python - seaborn中的图例重叠情节区域
- angular - 映射接口到 json 数据