Shiny中highchartProxy更新packedbubble系列动画时长设置异常
问题:HighchartProxy更新Packed Bubble系列时动画时长设置无效
在Shiny中使用highchartProxy工具集,想要通过hcpxy_set_data函数(开启updatePoints=T)更新packedbubble系列数据时,将动画时长设置为6000毫秒。但实际测试发现,该设置对column系列能正常生效,动画会按指定时长播放,然而对packedbubble系列完全无效,更新动画瞬间完成,hcpxy_set_data的animation参数似乎被忽略。
原本以为这是packedbubble系列的模拟选项覆盖了动画设置,但即使禁用模拟算法(layoutAlgorithm = list(enableSimulation=F)),还是无法控制动画时长。
以下是用于对比column和packedbubble系列动画效果的示例应用:
library(tidyverse) library(highcharter) library(shiny) # UI #================================================================================ column <- purrr::partial(shiny::column, width = 6) ui <- fluidPage( tags$hr(), actionButton("reset", "Reset charts", class = "btn-danger"), tags$hr(), fluidRow( column( actionButton("set_column_data", "Update column series"), highchartOutput("hc_set_column_data") ), column( actionButton("set_bubble_data", "Update bubble series"), highchartOutput("hc_set_bubble_data") ) ) ) # Server #============================================================================== server <- function(input, output, session){ # Create original series #---------------------------------- # Column output$hc_set_column_data <- renderHighchart({ input$reset df <- data.frame( month = month.abb, A = c(rep(20, 11), 30), B = c(rep(5, 11), 30), C = c(rep(18, 11), 30), D = c(rep(80, 11), 30) ) %>% tidyr::pivot_longer(A:D, names_to = "name", values_to = "value") hchart(df, "column", hcaes(month, value, group = name)) %>% hc_xAxis(title = list(text = "")) %>% hc_yAxis(title = list(text = "")) }) # Bubble output$hc_set_bubble_data <- renderHighchart({ input$reset d <- data.frame( name = c('G1', 'G2'), value = c(1, 1) ) hchart(d, "packedbubble", hcaes(name = name, value = value)) %>% hc_plotOptions( packedbubble = list( colorByPoint=T, layoutAlgorithm = list( enableSimulation=F ) ) ) }) # Update single point in series #----------------------------------------- # Column observeEvent(input$set_column_data, { df <- data.frame( month = month.abb, A = c(rep(20, 11), 30), B = c(rep(5, 11), 30), C = c(rep(18, 11), 30), D = c(rep(80, 11), 90) ) %>% tidyr::pivot_longer(A:D, names_to = "name", values_to = "value") highchartProxy("hc_set_column_data") %>% hcpxy_set_data( type = "column", data = df, mapping = hcaes(month, value, group = name), redraw = TRUE, updatePoints=T, animation =list(enabled=T, duration=6000) ) }) # Bubble observeEvent(input$set_bubble_data, { d <- data.frame( name = c('G1', 'G2'), value = c(4, 1) ) highchartProxy("hc_set_bubble_data") %>% hcpxy_set_data( type = "packedbubble", data = d, mapping = hcaes(name=name, value=value), redraw = T, updatePoints=T, animation =list(enabled=T, duration=6000) ) }) }) shiny::shinyApp(ui, server)
内容的提问来源于stack exchange,提问作者tibblah
相关产品推荐
相关产品推荐

