gpt4 book ai didi

r - Shiny + SQLite - 为什么Shiny 非常慢?

转载 作者:行者123 更新时间:2023-12-01 22:35:00 29 4
gpt4 key购买 nike

我们开发 Shiny 应用程序已经有几个月了。但是,当我们的 Shiny 应用尝试加载大量数据时,它会极其缓慢。我们甚至使用reactive函数来重用数据。但是当我们请求不同的数据集时,它仍然像以前一样慢。

我们有一个日志文件,它显示 Shiny 每次从我们的数据库加载数据至少需要 30.12672 秒或 52.24799 秒。

Shiny 这么慢的原因是什么?是服务器还是数据库?我们可以做些什么来加快速度?

我们正在使用 SQLite 数据库。这是让Shiny变慢的原因吗?

如果是这样,我们还应该选择什么类型的数据库系统来处理大量数据集? Cassandra ?数据库? Apache Spark ?

编辑:

例如,

query <- "SELECT
s.timestamp,
s.particle_concentration as `PM2.5`,
n.code as site
FROM speckdata AS s

LEFT JOIN nodes AS n
ON n.nid = s.nid
AND n.datatype = 'speck'

WHERE strftime('%Y', s.localdate) = 'YEAR'
"

# Match the pattern and replace it.
dataQuery <- sub("YEAR", as.character(year), query)

# Store the result in data1.
data = dbGetQuery(DB, dataQuery)

if(nrow(data) > 0) {

# Convert timestamp to date and bind it to the data.
data$date <- as.POSIXct(as.numeric(as.character(data$timestamp)), origin="1970-01-01", tz="GMT")
}


# Chosen to group the data in one panel.
timePlot(
data,
pollutant = c(species, condition),
avg.time = avg_time,
lwd = 2,
lty = 1,
name.pol = c(species_text_value, condition_text_value),
type = "site",
group = TRUE,
auto.text = FALSE
)

这在 Shiny 中非常慢。

但是当我们使用 SQLite 管理器查询数据集时,只需要 1.9 秒即可查询 4719282 行!

enter image description here

最佳答案

我建议直接从数据库测试 SQLite 查询的性能。如果这是您的慢点,您将需要优化查询以使其更加高效。在我提供进一步帮助之前,最好先准确了解性能问题出在哪里。

关于r - Shiny + SQLite - 为什么Shiny 非常慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31759200/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com