0
我已經編寫了下面的代碼來上傳文件並在點擊Go按鈕後進行一些計算。但是,下面的代碼每次都會執行文件加載,即使我沒有再次上傳文件。我不想再次加載文件。隔離文件的加載
**Server.R**
options(shiny.maxRequestSize = 400*1024^2)
shinyServer(function(input, output,session) {
datasetInput <- reactive({
progress <- shiny::Progress$new()
# Make sure it closes when we exit this reactive, even if there's an error
on.exit(progress$close())
progress$set(message = "Processing is going on..Kindly wait")
isolate({
S <- input$file1
T <- input$file2
if (is.null(S))
return(NULL)
Startrpt<-read.csv(S$datapath, header=TRUE)
if (is.null(T))
return(NULL)
Takeoffrpt<-read.csv(T$datapath, header=TRUE)
Takeoffrpt$TkDates = as.POSIXct(Takeoffrpt$Date,format='%m/%d/%Y %H:%M')
Startrpt$StDates = as.POSIXct(Startrpt$Date,format='%m/%d/%Y %H:%M')
# Getting only Dates
Takeoffrpt$TkDate1 = as.Date(Takeoffrpt$TkDates)
Startrpt$StDate1=as.Date(Startrpt$StDates)
# Getting only Time
Takeoffrpt$TkTime = format(Takeoffrpt$TkDates,'%H:%M')
Startrpt$StTime=format(Startrpt$StDates,'%H:%M')
Takeoffrpt$TkMins<-as.numeric(substring(Takeoffrpt$TkTime,1,2))*60+as.numeric(substring(Takeoffrpt$TkTime,4,5))
Startrpt$StMins<-as.numeric(substring(Startrpt$StTime,1,2))*60+as.numeric(substring(Startrpt$StTime,4,5))
})
query<-paste("select tk.*,st.*,tk.Date as Tkdate, st.Date as Stdate, (tk.TkMins-st.StMins) as difference from Takeoffrpt as tk inner join Startrpt as st on tk.ESN=st.ESN and tk.TkDate1=st.StDate1 AND (tk.TkMins-st.StMins) <= ", input$Range," and (tk.TkMins-st.StMins) >= 0",sep="")
P<-sqldf(query,drv="SQLite")
P<-subset(P, select=-c(Date,TkDates,TkDate1,TkTime,TkMins,StDates,StDate1,StTime,StMins,difference))
write.csv(file="output.csv",P)
#data1<-sqldf("select * from Startrpt",drv="SQLite")
})
output$view <- renderDataTable({
if (input$goButton == 0)
return()
isolate(datasetInput())
}, options = list(lengthMenu = c(5, 10, 15), pageLength = 5))
})
**ui.R**
rm(list=ls())
packages <- c("sqldf", "shiny")
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())))
}
library(shiny)
library(sqldf)
shinyUI(fluidPage(
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose your Start Report CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
fileInput('file2', 'Choose your take off Report CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
# Sidebar with a slider input for number of observations
sliderInput("Range",
"Accepted Minutes difference",
min = 1,
max = 60,
value = 1),
actionButton("goButton", "Go!")
#submitButton("Apply")
),
mainPanel(
dataTableOutput("view")
)
)
))
謝謝..我已經解決了這個問題 – Surya