I have browsed on SO and the R community, it looks like this error may result from vary reasons, so I still post my problem here, please give me some suggestions. Thank you very much.
Here is the code that works locally:
library(shiny)
ui=fluidPage(
titlePanel('hello shiny'),
sidebarPanel(
textInput('ID',label='ID:'),actionButton('goButton',label='submit')
),
mainPanel(imageOutput('out'))
)
server <- function(input, output,session) {
fullnames=list.files(path = "/Users/u/myapp/www", pattern = ".png");
reactive({
input$ID=gsub(pattern = '\\.png','',fullnames)
}
);
output$out=renderImage(
{
filenames=normalizePath(file.path('/Users/u/myapp/www',paste(input$ID,'.png',sep='')));
list(src=filenames)
},
deleteFile = F
)
}
shinyApp(ui,server)
however, there is a warning:
Listening on http://127.0.0.1:7453
Warning in normalizePath(file.path("/Users/u/myapp/www", paste(input$ID, :
path[1]="/Users/ya/myapp/www/.png": No such file or directory
I guess it is the input that caused this error, but the similar warning on the server log shows that there is an ID '20191704465.png' in the code (the ID I fill in in the textInput widget):
2021-08-12T13:32:22.863287+00:00 shinyapps[4485062]: Listening on http://127.0.0.1:38432
2021-08-12T13:32:26.831219+00:00 shinyapps[4485062]: path[1]="/Users/u/myapp/www/.png": No such file or directory
2021-08-12T13:32:26.831217+00:00 shinyapps[4485062]: Warning in normalizePath(file.path("/Users/u/myapp/www", paste(input$ID, :
2021-08-12T13:32:31.471638+00:00 shinyapps[4485062]: path[1]="/Users/u/myapp/www/20191704465.png": No such file or directory
but somehow the server still shows:
path[1]="/Users/u/myapp/www/20191704465.png": No such file or directory
What went wrong with the code?
While it can run locally with
path = "/Users/u/myapp/www"
,
it is best to specify relative path while running on shiny server as
path = "./www"