简体   繁体   中英

Error in rendering Highcharter Pie chart in Shiny App

I am trying to plot a pie chart using highcharter in a Shiny app with 2 user controls. Here's the relevant UI code:

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')
                )

And this is the server code for rendering the chart:

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"))
})

This returns in the following error:

Warning: Error in mutate_impl: Column `x` is of unsupported type quoted call

Can't figure out why. Here's some test data:

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"))

I am using version 0.6.0 of highcharter .

While I am still trying to wrap my head around tidyeval, as I feel that might be the problem, here's a quick, though not the most elegant of hacks which works:

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"))
})

Just added a column name rather than the input$type .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM