加载ggplot2后,Highcharter绘图失败
在我的闪亮应用程序中,我想创建一个线条图,其中加载ggplot2后,Highcharter绘图失败,r,ggplot2,shiny,r-highcharter,R,Ggplot2,Shiny,R Highcharter,在我的闪亮应用程序中,我想创建一个线条图,其中组值基于所选的用户输入:input$tt_groupvar。Highcharter可以使用hcaes\u string实现这一点,但现实生活中我的应用程序加载ggplot2,而hchart失败 在下面的app1中,未显式加载ggplot2,并且绘图根据input$tt_groupvar对数据进行正确分组。但在下面的app2中,唯一的区别是加载了ggplot2,应用程序失败。通过app2加载ggplot2后,app1不再正常工作 我知道我可以使用ggp
组
值基于所选的用户输入:input$tt_groupvar
。Highcharter可以使用hcaes\u string
实现这一点,但现实生活中我的应用程序加载ggplot2,而hchart
失败
在下面的app1中,未显式加载ggplot2,并且绘图根据input$tt_groupvar
对数据进行正确分组。但在下面的app2中,唯一的区别是加载了ggplot2,应用程序失败。通过app2加载ggplot2后,app1不再正常工作
我知道我可以使用ggplot2或plotly使其正常工作,但我真的想使用highcharter。有没有办法绕过这个问题
任何洞察都是非常感谢的
附件1
库(闪亮)
图书馆(dplyr)
图书馆(高级特许)
df%
hc#u yAxis(title=list(text=“#of ROCs”))%>%
hc_标题(text=“2017年至2019年1月集团每月ROC数量”)
})
}
shinyApp(用户界面、服务器)
附件2
图书馆(闪亮)
图书馆(dplyr)
图书馆(高级特许)
图书馆(GG2)
df%
hc#u yAxis(title=list(text=“#of ROCs”))%>%
hc_标题(text=“2017年至2019年1月集团每月ROC数量”)
})
}
shinyApp(用户界面、服务器)
如果您不想使用它,而您有一个没有它的工作版本,为什么要加载ggplot
?我在github上发现了一个关于的问题。我知道这个问题与某些版本的rlang
和ggplot2
有关。有可能升级这些软件包吗?@andrew_reece,很抱歉不够清晰。在现实生活中,我的实际应用程序有其他选项卡,并为应用程序的其他部分加载ggplot2,因此我似乎无法避免导致问题的原因highcharter
。我真的希望用这种方式在我的应用程序中使用highcharter
,加载ggplot2
会使它无法使用。我这样写这篇文章是为了证明我认为罪魁祸首是ggplot2
。希望这有助于澄清这一点。@ricoderks,谢谢你的建议,但我重新安装了ggplot2(3.2.1)、rlang(0.4.4)和highcharter(0.7.0)以获得最新版本,问题仍然存在。可能是因为我没有最新版本的R?我使用的是R版本3.6.0.aah垃圾,抱歉@jpopel!!只是注意到我没有加载ggplot2
。我尝试了太多的事情,以至于我没有注意到!!我将删除我的答案!!
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)
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)