【发布时间】:2022-08-14 07:57:08
【问题描述】:
我在下面有一个闪亮的应用程序,其中我正在使用库highchart、ggplot 和plotly 在iris 数据集上绘制散点图。
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 框动态绘制图表。
这是问题 -
- 我在
selectInput框中选择了一个物种,highchart库绘制了一个散点图 - 然后我在单选按钮部分选择
plotly并使用plotly 完成渲染。 - 我更改了
selectInput和plotly中的物种重新渲染了情节 - 现在,当我单击
highchart单选按钮时,将绘制早期物种(来自缓存)的图几秒钟,然后绘制所选物种的图表。问题有没有办法清除或禁用缓存,以免出现渲染延迟?