Why does running a shiny app in r studio show all the images that are added by html but not when running it in the batch?
For example, I have this simple app that calls an html file that contains 2 images, in r studio the app looks perfectly but when in command it doesn't work.
It doesn't show any kind of error or warning just like it doesn't recognize the image.
How can it be corrected?
app.R
library(shiny)
ui <- tagList(
includeHTML("www/htmlFile.html")
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
htmlFile.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>page1</title>
</head>
<body>
<h3>Hello world!!</h3>
<img src="img1.jpg"/>
<img src="img2.jpg"/>
</body>
</html>
So I run the shiny app from the command line:
R.exe CMD BATCH app.R
CodePudding user response:
We can try renderImage
. Here's an example:
# download some images and save them in the project directory
download.file("https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/R_logo.svg/1200px-R_logo.svg.png", destfile = "r.png")
download.file("https://pngset.com/images/r-logo-r-programming-language-logo-text-building-alphabet-dryer-transparent-png-2749164.png", destfile = "r2.png")
library(shiny)
ui <- fluidPage(
withTags(
head(meta(`http-equiv` = "content-type", content = "text/html; charset=utf-8", title("page1")))
),
h3("Hello World!!"),
imageOutput("img1"),
imageOutput("img2")
)
server <- function(input, output, session) {
output$img1 <- renderImage({
list(
src = "r.png",
width = 250,
hight = 250
)
}, deleteFile = TRUE)
output$img2 <- renderImage({
list(
src = "r2.png",
width = 250,
hight = 250
)
}, deleteFile = TRUE)
}
shinyApp(ui, server)
CodePudding user response:
I managed to fix it by running another script that runs the app.R
run.R
shiny :: runApp ('app.R')
In command:
"R.exe" CMD BATCH "run.R"