我正在处理此处询问的相同程序,但对服务器代码进行了一些修改。这是它的更新版本:
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)}
})
}
我尝试执行这些代码以及来自上述链接的 UI 代码,shinyApp(ui = ui, server = server)
这次我在 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)}
})
}
起初程序似乎没有问题(基本上像这样),但是在我上传 *.xls 或 *.xlsx 文件后问题仍然存在(如这里所示)。此外,当我尝试使用 对其进行故障排除时traceback()
,R 的唯一响应是No traceback available
.
PS:再次,请原谅我的语言,我在上面的程序中使用印度尼西亚语。