【问题标题】:Shiny cache causes delay in rendering with renderUI闪亮的缓存会导致使用 renderUI 进行渲染延迟
【发布时间】:2022-08-14 07:57:08
【问题描述】:

我在下面有一个闪亮的应用程序,其中我正在使用库highchartggplotplotlyiris 数据集上绘制散点图。

library(shiny)
library(shinydashboard)
library(highcharter)
library(shinyWidgets)
library(plotly)
library(ggplot2)
library(data.table)

siderbar <- dashboardSidebar(
  sidebarMenu(
    # Add buttons to choose the way you want to select your data
    selectizeInput(inputId = \"inp_species\", label = \"Select by:\", choices = c(\"setosa\", \"versicolor\", \"virginica\"), selected = \"setosa\"),
    awesomeRadio(inputId = \"radioTest\", label = \"Choose one:\",
                 choices=c(\"High Charter\" = \"highcharter\",
                           \"Simple Plot\" = \"simple\",
                           \"Plotly\" = \"plotly\"),
                 inline = FALSE, selected = \"highcharter\")
  )   
)

body <- dashboardBody(
  fluidRow(
    tabBox(
      side = \"right\",
      selected = \"Tab1\",
      tabPanel(\"Tab1\", \"Tab content 1\", uiOutput(\"tabset1Selected\"))
    )
  ),
)

shinyApp(
  ui = dashboardPage(
    dashboardHeader(title = \"tabBoxes\"),
    siderbar,
    body
  ),
  
  server = function(input, output, session) {
    
  iris_dt <- reactive({
    iris_table = data.table(copy(iris))
    iris_table[Species == input$inp_species]
    })
  
   render_content <-  reactive({
     req(input$radioTest)
     print(input$radioTest)
      if(input$radioTest==\'highcharter\'){
      output$plot1 <-   renderHighchart({
        highchart() %>%
          hc_add_series(iris_dt(), type = \"scatter\", hcaes(x = Petal.Width, y = Sepal.Length))
        })
      out <- highchartOutput(\"plot1\")
      }

      
      else if(input$radioTest==\'plotly\'){
        output$plot2 <- renderPlotly({
          plot_ly(iris_dt(), x = ~ Petal.Width, y = ~ Sepal.Length)
        })
        out <- plotlyOutput(\"plot2\")
      }
     
     
     else if(input$radioTest==\'simple\'){
       output$plot3 <- renderPlot({
         ggplot(iris_dt(), aes(x =  Petal.Width, y = Sepal.Length)) + geom_point()
       })
       out <- plotOutput(\"plot3\")
      
     }
     
     return(out)
    })
    
    
    # The currently selected tab from the first box
    output$tabset1Selected <-  renderUI({
      render_content()
    })
    

    
  }
)

我正在选择库以使用 selectInput 框动态绘制图表。

这是问题 -

  1. 我在selectInput 框中选择了一个物种,highchart 库绘制了一个散点图
  2. 然后我在单选按钮部分选择plotly 并使用plotly 完成渲染。
  3. 我更改了selectInputplotly 中的物种重新渲染了情节
  4. 现在,当我单击highchart 单选按钮时,将绘制早期物种(来自缓存)的图几秒钟,然后绘制所选物种的图表。

    问题有没有办法清除或禁用缓存,以免出现渲染延迟?

    标签: r shiny


    【解决方案1】:

    我们可以禁用动画效果。虽然这不是解决问题的方法,但它可以同时提供帮助。

          output$plot1 <- renderHighchart({
              highchart() %>%
                hc_add_series(
                  data = iris_dt(),
                  type = "scatter",
                  hcaes(x = Petal.Width, y = Sepal.Length)
                ) %>%
                hc_plotOptions(
                  series = list(
                    animation = FALSE
                  )
                )
    

    【讨论】:

      猜你喜欢
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 2015-10-27
      • 2020-11-14
      • 1970-01-01
      相关资源
      最近更新 更多