我有3个以下的文件(Retrieve_AOI_Utilization.R,ui.R,server.R)
# Retrieve_AOI_Utilization.R
library(lubridate)
library(RODBC)
myconn<- odbcConnect("pfods", uid = "testingt", pwd = "****")
systemtype <- '0043-004'
startDate <- "08/12/2014" # DD/MM/YYYY format
endDate <- "11/12/2014" # DD/MM/YYYY format
TimeDiff <- as.Date(as.character(endDate), format="%d/%m/%Y")- as.Date(as.character(startDate), format="%d/%m/%Y")
TimeDiff <-as.data.frame(TimeDiff)
nDays <- TimeDiff$TimeDiff[[1]]
conveyortime <- 25
querytest <- paste("SELECT distinct MONO, LASTUPDATE, SYSTEMTYPE, TESTTIME
FROM PFODS.PPLPRODUCTAOI
WHERE SYSTEMTYPE = '",systemtype,"'
AND LASTUPDATE >= todate('",startDate,"','DD/MM/YYYY')
AND LASTUPDATE <= todate('",endDate,"','DD/MM/YYYY')
AND TESTTIME IS NOT NULL
ORDER BY LASTUPDATE ASC, MONO" , sep="")
test <- sqlQuery(myconn, query_test)
testtime <- test$TESTTIME
HourMinSec <-strftime(testtime, format="%H:%M:%S")
TotalTimeInSec <- periodtoseconds(hms(HourMinSec)) # convert to total seconds
Utilization = (sum(TotalTimeInSec) + nrow(test)conveyor_time)/ (nDays24*3600) *100
# ui.R
shinyUI(fluidPage(
titlePanel("TestSystem Utilization for AOI Machines in SMT."),
sidebarLayout(
sidebarPanel(
helpText("Select a TestSystem and Date Range and press Submit button to retrieve its Utilization value."),
selectInput("var",
label = "Select a TestSystem",
choices = list("0043-001","0043-002","0043-003","0043-004","0043-A067-001","0043-A067- 003"),
selected = "0043-001")
),
mainPanel(
textOutput("text1")
)
)
))
# server.R
Utilization <- source('Retrieve_AOI_Utilization.R')
shinyServer(
function(input, output) {
#Utilization <- 50
specify_decimal <- function(x, k) format(round(x, k), nsmall=k)
output$text1 <- renderText({
paste("TestSystem", input$var, "has Utilization value of", specify_decimal(Utilization$value, 2),"%")
})
}
)
如果我直接从Utilization&lt; - 50中检索Utilization值,那么应用程序在Shiny Server中运行完全正常。
我在localhost中看到,当从&#34; Utilization&lt; - source(&#39; Retrieve_AOI_Utilization.R&#39;)&#34;中检索到Utilization值时,它正在工作。 ,见下面的版画屏幕: http://imgur.com/8h24p5h
但是,如果我从源(&#39; Retrieve_AOI_Utilization.R&#39;)中检索Utilization值并部署到Shiny服务器,则应用程序将以灰色屏幕挂起,如下所示: http://imgur.com/BcqwMfb
为什么会这样? 请帮忙。
答案 0 :(得分:0)
首先,您有两个不同的文件:Retrieve_AOI_Utilization.R
和RetrieveAOIUtilization.R
吗?你是故意使用它们还是应该使用它?因为您只显示了后者的代码。
其次,如果您在浏览器上按F12时在闪亮的服务器上崩溃,请转到&#34;控制台&#34;选项卡,可以在那里显示您的R代码中断的行。你可以从这一点进行调试。
修改强>
您有以下连接:
myconn<- odbcConnect("pfods", uid = "testingt", pwd = "****")
您确定可以连接到您托管pfods
的{{1}} ODBC连接器吗?一定要有相同的ODBC,数据库,用户名和密码。