r - 在 R 闪亮的作品中阅读 excel 很慢
问题描述
我有一个闪亮的应用程序,它应该首先从两个 excel 文件中提取/读取数据,然后使用响应式自定义 excel 文件的结果以生成两个表。问题是excel文件很重,应用程序需要花费大量时间来读取excel文件。它还减慢了反应性响应时间。下面是一个解释我的应用程序结构的虚拟代码。
library(readxl)
ui <- fluidPage(
tableOutput('dt1'),
tableOutput('dt2'),
selectInput('choice','TLT Select',choices= c('Yes','No'))
)
server <- shinyServer(function(input, output){
t.1 a <-as.data.frame(read_excel(path ="A.xlsx") ,stringsAsFactors = FALSE) #this is a 45 MB excel file
t.2 <- a <-as.data.frame(read_excel(path ="B.xlsx") ,stringsAsFactors = FALSE) # this is a 50 MB excel file
excel.a <- reactive({
if (input$choice == 'Yes') {
subset(t.1, t.1$Action == 'Yes') }
else
{subset(t.1, t.1$Action == 'No')}
excel.b <- reactive({
if (input$choice == 'Yes') {
subset(t.2, t.2$Action == 'Yes') }
else
{subset(t.2, t.2$Action == 'No')}
output$dt1 <- renderTable({
excel.1()
})
output$dt2 <- renderTable({
excel.2()
})
})
}
shinyApp(ui, server)
这当然不是一个可重现的示例,但这就是我的查询的结构。任何想法如何使它更高效和更快,以便它快速加载并且反应响应也更快?
谢谢
解决方案
在浏览器中尝试或添加“浏览”按钮。添加到服务器,例如:
data <- reactive({
validate(
need(input$file != "", "Please select a data set !!!\nUse 'Browse' bottom to choose\n")
)
inFile <- input$file
if (is.null(inFile))
return(NULL)
a <-as.data.frame(read_excel(inFile$datapath) ,stringsAsFactors = FALSE)
....... # all manipulation
# and in UI
fileInput("file", "Choose Date file:",accept = c('.xlsx')
可能这不是文件下载时间,可能是 HTML css 等格式的表示数据的时间
推荐阅读
- javascript - 有没有办法将 css 应用于元素的一部分?
- javascript - 我不断收到错误:require is not defined
- google-chrome-theme - 有没有办法为操作系统中的明暗模式指定不同的 Chrome 主题颜色?
- c++ - 为什么 Visual Studio 只返回整数?
- python - 按长期月平均年查找变异性月度数据
- ruby - RSpec shared_examples 有条件地检查块是否存在
- reactjs - 列表组件不断重新渲染
- ajax - 如何使用带有 Ajax 和 Laravel 的 id 从另一个表中获取值?
- c# - 我正在尝试在 NET 5 核心中创建 TexttoSpeech。为此,swagger UI 在 webapi 中没有显示任何内容
- node.js - 你可以使用 axios 在后端发出 post 请求吗?