You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

加载TSclust包后调用ggplotly()致RStudio会话崩溃求助

RStudio加载TSclust后ggplotly触发会话挂起崩溃问题

问题现象

  • 调用ggplotly()后RStudio会话直接挂起,无法通过GUI正常关闭,只能借助系统监视器强制终止进程
  • 首次运行ggplotly()示例代码完全正常,但加载TSclust包后再次执行相同代码,会出现无视图输出且会话挂起的情况
  • 问题仅在特定项目中出现,该项目未加载额外数据或第三方包

复现代码

require(ggplot2)
require(plotly)

data(canada.cities, package = "maps")
viz <- ggplot(canada.cities, aes(long, lat)) +
  borders(regions = "canada") +
  coord_equal() +
  geom_point(aes(text = name, size = pop), colour = "red", alpha = 1/2)
ggplotly(viz, tooltip = c("text", "size"))
# 首次运行正常
# 清空Viewer窗格后执行以下代码
require(TSclust)
ggplotly(viz, tooltip = c("text", "size"))
# 无输出,R会话直接挂起

会话信息

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Pop!_OS 22.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=es_ES.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=es_ES.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=es_ES.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C        

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base      

other attached packages:
[1] TSclust_1.3.1 cluster_2.1.2 pdc_1.0.3     plotly_4.10.3 ggplot2_3.4.4

loaded via a namespace (and not attached):
 [1] rgl_1.2.1              Rcpp_1.0.11            lattice_0.20-45        tidyr_1.3.0            class_7.3-20           zoo_1.8-12             digest_0.6.33         
 [8] lmtest_0.9-40          utf8_1.2.3             R6_2.5.1               httr_1.4.7             pillar_1.9.0           rlang_1.1.1            lazyeval_0.2.2        
[15] curl_5.1.0             misc3d_0.9-1           rstudioapi_0.15.0      data.table_1.14.8      fracdiff_1.5-2         TTR_0.24.3             labeling_0.4.3        
[22] htmlwidgets_1.6.2      munsell_0.5.0          proxy_0.4-27           compiler_4.1.2         xfun_0.40              pkgconfig_2.0.3        base64enc_0.1-3       
[29] forecast_8.21.1        urca_1.3-3             htmltools_0.5.6.1      tcltk_4.1.2            nnet_7.3-17            tidyselect_1.2.0       tibble_3.2.1          
[36] quadprog_1.5-8         dtw_1.23-1             fansi_1.0.5            viridisLite_0.4.2      dplyr_1.1.3            withr_2.5.1            grid_4.1.2            
[43] nlme_3.1-155           jsonlite_1.8.7         gtable_0.3.4           lifecycle_1.0.3        magrittr_2.0.3         scales_1.2.1           KernSmooth_2.23-20    
[50] quantmod_0.4.25        cli_3.6.1              longitudinalData_2.4.5 tseries_0.10-54        timeDate_4022.108      ellipsis_0.3.2         xts_0.13.1            
[57] generics_0.1.3         vctrs_0.6.4            tools_4.1.2            glue_1.6.2             purrr_1.0.2            clv_0.3-2.4            maps_3.4.1.1          
[64] crosstalk_1.2.0        parallel_4.1.2         fastmap_1.1.1          yaml_2.3.7             colorspace_2.1-0       locpol_0.8.0           knitr_1.44 

解决方案建议

  1. 分时加载包:如果不需要同时使用两个包,调用ggplotly前用detach("package:TSclust", unload=TRUE)卸载TSclust,完成可视化后再重新加载TSclust处理时序聚类任务。
  2. 更新包版本:当前使用的TSclust 1.3.1是较旧版本,尝试更新到CRAN最新稳定版,同时同步更新plotly、ggplot2及其依赖包,大概率能修复包间兼容性冲突。
  3. 分离会话执行:将需要TSclust的代码和需要ggplotly的代码放在不同R会话中运行,从根源上避免包冲突。
  4. 排查函数冲突:加载TSclust后执行conflicts(detail=TRUE),查看是否存在与plotly、ggplot2重叠的函数,针对性用::指定包名调用函数(如plotly::ggplotly())。

内容的提问来源于stack exchange,提问作者user2955884

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 03:12:07