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

renderSlickR设置dots=TRUE后图表不替换重复生成问题求助

问题:slickR添加dots参数后Shiny输入更新时图表重复渲染
  • 使用renderSlickR根据输入选择构建图表轮播,未设置dots=TRUE参数时,轮播可正常响应输入变化;但添加该参数后,每次更改输入选项,新的图表轮播会直接生成在旧轮播下方,不会替换原有内容。
  • 以下是用iris数据集复现问题的代码:
# Load required packages
if (!require(pacman))
  install.packages("pacman")

#Not all these packages are needed here, obviously
pacman::p_load(
  R.devices,
  shiny,
  magrittr,
  dplyr,
  ggplot2,
  shinyWidgets,
  svglite,
  slickR,
  ggpubr
)

# Load iris dataset
data(iris)

# Define UI
ui <- fluidPage(
  # Sidebar panel for inputs
  sidebarPanel(
    # Select x-axis variable
    selectInput("choice", "X-axis variable", choices = c(100, 150)),
  ),
  # Main panel for output
  mainPanel(
    # Plot output
    slickROutput("plot")
  )
)

# Define server
server <- function(input, output, session) {
  observe({
    fig_list = list()
    for (i in 1L:2L){ #Creating two plots to make a carousel
      fig_list[[i]] <- 
        {
          svglite::xmlSVG(
            code = {
              g = ggplot(iris[(40*i):input$choice, ], aes(x = Sepal.Length, 
                                                     y = Petal.Length)) +
                geom_point() 
              print(g)
            },
            standalone = T)
        }
    }
    output[["plot"]] = renderSlickR({
      slickR(fig_list, "plot") +
        settings(
          customPaging = htmlwidgets::JS(
            "function(slick,index) {
                            return '<a>'+(index+1)+'</a>';
                       }"
          ),
          dots = T #if we remove this, then only one plot is generated.
        )
    })
    
  })
}

# Run the application
shinyApp(ui = ui, server = server)

解决方案

该问题是slickR的已知bug,通过应用官方提供的修复补丁,已解决此问题。补丁修正了slickR在启用dots参数时的组件渲染逻辑,确保输入更新时新的轮播组件会正确替换旧内容,而非重复追加。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 20:15:06