Below please find another example trying to point out what Olivier is refering to. Using the "Run App" button the images are found, while they are not found when the following code is run via Run Selected Line(s)
or Ctrl+Enter
(my workaround can be seen above):
library(shiny)
# create some local images
if(!dir.exists("www")){
dir.create("www")
}
myImgNames <- paste0("myplot", seq_len(3), ".png")
myPlotPaths <- file.path("www", myImgNames)
for (myPlot in myPlotPaths) {
png(file = myPlot, bg = "transparent")
plot(runif(10))
dev.off()
}
ui <- fluidPage(
tags$img(src = myImgNames[1], width = "400px", height = "400px"),
tags$img(src = myImgNames[2], width = "400px", height = "400px"),
tags$img(src = myImgNames[3], width = "400px", height = "400px")
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
From ?runApp
appDir
The application to run. Should be one of the following:
A directory containing server.R, plus, either ui.R or a www directory that contains the file index.html.
A directory containing app.R.
An .R file containing a Shiny application, ending with an expression that produces a Shiny app object.
A list with ui and server components.
A Shiny app object created by shinyApp().
In other words we could say, that the contents of the www
folder aren't found for a Shiny app object created by shinyApp()
when executed via Run Selected Line(s)
:
However, my personal opinion is, that when you want to run a shiny app in RStudio use Ctrl+Shift+S
instead of Ctrl+A
(selection) and Ctrl+Enter
.