[英]read excel in R shiny works slow
I have a shiny app, that is supposed to first pull/read the data from two excel file, then use reactive to customize the results of excel files to produce two tables. 我有一个闪亮的应用程序,应该首先从两个excel文件中提取/读取数据,然后使用反应式自定义excel文件的结果以生成两个表。 Problem is that excel files are heavy , and app takes a lot of time to read excel files.
问题是excel文件很重,应用程序需要花费很多时间才能读取excel文件。 it also slows down the reactivity response time.
这也会减慢反应性响应时间。 Below is a dummy code that explain the structure of my app.
下面是一个虚拟代码,解释了我的应用程序的结构。
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)
This is of course not a reproduce able example , but this is how my query is structured. 这当然不是可复制的示例,但这就是我的查询的结构。 Any idea how to make it more efficient and faster , so that it loads quickly and reactive response is more faster as well ?
知道如何使它更高效,更快,从而使其加载更快并且响应速度也更快吗?
Thanks 谢谢
Try it in browser or add "browse" button. 在浏览器中尝试或添加“浏览”按钮。 Add to server something like:
向服务器添加如下内容:
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')
May be this is not a file download time, may be it is time for representation data in HTML css etc format 可能不是文件下载时间,可能是HTML css等格式的表示数据的时间
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.