r - 在 Shiny App 中渲染 Highcharter 饼图时出错
问题描述
highcharter
我正在尝试在带有 2 个用户控件的 Shiny 应用程序中绘制饼图。这是相关的用户界面代码:
column(
6,
fluidRow(
column(6,selectInput('type','Select Builder/Owner',
choices = c('Builder'="Builder",'Owner Group'="`Owner Group`"))),
column(6, sliderInput('minvsl',"Select minimum number of vessels",min=1,value=10,max=100))
),
highchartOutput('Builder',width='100%', height = '600px')
)
这是渲染图表的服务器代码:
output$Builder <- renderHighchart({
ByBuilder <- orderbook %>% dplyr::group_by_(input$type) %>% dplyr::summarise(Count=n()) %>%
filter(Count>=input$minvsl)
highchart() %>%
hc_add_series(ByBuilder,hcaes_(x=input$type,y="Count"), type="pie",
dataLabels=list(enabled=TRUE),innerSize= '40%', size ='80%',
tooltip=list(pointFormat = paste('{point.y} ships<br/><b>{point.percentage:.1f}%</b>'))) %>%
hc_add_theme(hc_theme_smpl()) %>%
hc_title(text = paste("Construction by", input$type))%>%
hc_subtitle(text = paste("Control the min. number of constructions by the numeric slider"))
})
这将返回以下错误:
Warning: Error in mutate_impl: Column `x` is of unsupported type quoted call
想不通为什么。下面是一些测试数据:
structure(list(Builder = c("Hyundai Mipo", "Onomichi Dockyd",
"Onomichi Dockyd", "Hyundai Mipo", "Hyundai Mipo", "Hyundai Mipo",
"Samsung HI", "Samsung HI", "Samsung HI", "Samsung HI"), `Owner Group` = c("SK Holdings",
"Nissen Kaiun", "Nissen Kaiun", "Overseas Shipholding", "Overseas Shipholding",
"Sonatrach Petroleum", "Mitsui & Co", "Mitsui & Co", "Mitsui & Co",
"Mitsui & Co")), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
我正在使用 0.6.0 版highcharter
。
解决方案
虽然我仍在努力解决 tidyeval 问题,但我觉得这可能是问题所在,这里有一个快速但不是最优雅的 hack 方法:
output$Builder <- renderHighchart({
ByBuilder <- orderbook %>% dplyr::group_by_(input$type) %>% dplyr::summarise(Count=n()) %>%
filter(Count>=input$minvsl)
colnames(ByBuilder)[1] <- "test"
highchart() %>%
hc_add_series(ByBuilder,hcaes(x='test',y="Count"), type="pie",
dataLabels=list(enabled=TRUE),innerSize= '40%', size ='80%',
tooltip=list(pointFormat = paste('{point.y} ships<br/><b>{point.percentage:.1f}%</b>'))) %>%
hc_add_theme(hc_theme_smpl()) %>%
hc_title(text = paste("Construction by", input$type))%>%
hc_subtitle(text = paste("Control the min. number of constructions by the numeric slider"))
})
只是添加了一个列名而不是input$type
.
推荐阅读
- ansible - 错误!'copy' 不是 Play 的有效属性
- c++ - 拥有“受保护的非虚拟析构函数”与“受保护的虚拟析构函数”有什么好处?
- python - 按列中选定行分组
- c - 如何使用 gcc 在 windows 上编译 LIBVLC 示例代码
- ios - 我的应用程序关闭后如何保存结构?
- mysql - Amazon RDS:您尝试将用户“master”连接到 MySQL 服务器失败
- matlab - 如何在 MATLAB 中对慢速代码进行矢量化以提高性能?
- c - 如果 (n!=0) n=0; v/sn=0;哪个更有效,为什么?
- python - 从 QComboBox 中选择字符串并将 ID 插入 SQLite db
- python - 使用 microsoft api 构建应用程序