我正在处理已经被问到here但在服务器代码中进行了一些修改的同一个程序。这是它的更新版本:
server <- function(input, output) {
dataset<-reactive({
inFile <- input$filewav
dat <- read_excel(inFile$datapath)
df <- data.frame(dat[,2], dat[,3])
x <- seq(1,nrow(df),length = nrow(df))
y <- df[,2]
return(dat)
})
output$plot_mra <- renderPlot({
filt <- switch(input$filterwav,
"Haar (d2)" = ls()[5],
"d4" = ls()[7],
"d6" = ls()[9],
"d8" = ls()[11],
"s4" = ls()[13],
"s6" = ls()[15],
"s8" = ls()[17],
"c6" = ls()[3],
"c12" = ls()[1])
set.seed(2)
inFile <- input$filewav
dat <- read_excel(inFile$datapath)
df <- data.frame(dat[,2], dat[,3])
x <- seq(1,nrow(df),length = nrow(df))
y <- df[,2]
y.mra <- mra(y,filt,input$reswav,"periodic",TRUE,"modwt")
if(input$reswav==0)
{plot(x,y, ylab = "", type = "p", col = "red")
mtext("Fungsi Asli", side = 3, line = 0.1)}
else
mra.y <- switch(input$reswav,
"1" = y.mra()@S$S1,
"2" = y.mra()@S$S2,
"3" = y.mra()@S$S3,
"4" = y.mra()@S$S4,
"5" = y.mra()@S$S5,
"6" = y.mra()@S$S6,
"7" = y.mra()@S$S7,
"8" = y.mra()@S$S8,
"9" = y.mra()@S$S9,
"10" = y.mra()@S$S10)
{plot(x,y, ylab = "", type = "p", col = "red")
par(new = TRUE)
plot(x,mra.y, ylab = "y", xlab = "x", type = "l", col = "blue")
mtext("Hasil Analisis Multiresolusi dengan MODWT", side = 3, line = 0.1)}
})
}
我尝试使用前面提到的shinyApp(ui = ui, server = server)
链接执行这些代码和UI代码,这次我在R控制台中遇到了这个错误:
Warning: Error in switch: EXPR must be a length 1 vector
Stack trace (innermost first):
105: excel_format
104: read_excel_
103: read_excel
102: renderPlot [#25]
92: <reactive:plotObj>
81: plotObj
80: origRenderFunc
79: output$plot_mra
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
我可能出错的任何想法?我该怎么办呢?
更新:好的,我根据Gregor de Cillia的建议编辑了我的服务器代码。这是它的更新版本:
server <- function(input, output) {
dataset<-reactive({
inFile <- input$filewav
dat <- read_excel(inFile$datapath)
df <- data.frame(dat[,2], dat[,3])
x <- seq(1,nrow(df),length = nrow(df))
y <- df[,2]
return(dat)
})
output$plot_mra <- renderPlot({
read_excel(req(input$filewav))
filt <- switch(input$filterwav,
"Haar (d2)" = ls()[5],
"d4" = ls()[7],
"d6" = ls()[9],
"d8" = ls()[11],
"s4" = ls()[13],
"s6" = ls()[15],
"s8" = ls()[17],
"c6" = ls()[3],
"c12" = ls()[1])
set.seed(2)
inFile <- input$filewav
dat <- read_excel(inFile$datapath)
df <- data.frame(dat[,2], dat[,3])
x <- seq(1,nrow(df),length = nrow(df))
y <- df[,2]
y.mra <- mra(y,filt,input$reswav,"periodic",TRUE,"modwt")
if(input$reswav==0)
{plot(x,y, ylab = "", type = "p", col = "red")
mtext("Fungsi Asli", side = 3, line = 0.1)}
else
mra.y <- switch(input$reswav,
"1" = y.mra()@S$S1,
"2" = y.mra()@S$S2,
"3" = y.mra()@S$S3,
"4" = y.mra()@S$S4,
"5" = y.mra()@S$S5,
"6" = y.mra()@S$S6,
"7" = y.mra()@S$S7,
"8" = y.mra()@S$S8,
"9" = y.mra()@S$S9,
"10" = y.mra()@S$S10)
{plot(x,y, ylab = "", type = "p", col = "red")
par(new = TRUE)
plot(x,mra.y, ylab = "y", xlab = "x", type = "l", col = "blue")
mtext("Hasil Analisis Multiresolusi dengan MODWT", side = 3, line = 0.1)}
})
}
程序中似乎没有问题(basically like this),但是在我上传* .xls或* .xlsx文件(as seen here)后问题仍然存在。另外,当我尝试使用traceback()
对其进行问题排查时,R的唯一回复是No traceback available
。
PS:再次请原谅我的语言,我在上面的节目中使用了印度尼西亚语。