I am trying to work through the R Studio Shiny tutorials. The second tutorial includes embedding an image into an app. It seems straight-forward and a similar question-and-answer here seems to use the same approach:
However, I cannot get this approach to work. Here is a stripped-down version of R Studio's second tutorial code and a screenshot of the result I get. I have the png file in my working directory. Must the photo be placed somewhere else?
setwd('C:/Users/mark_/Documents/RShiny/')
library(shiny)
ui <- fluidPage(
titlePanel('Shiny App with Photo'),
sidebarLayout(
sidebarPanel(
h2("Installation"),
p("Shiny is on CRAN"),
br(),
img(src = "myScreenshot.png", height = 70, width = 200),
br()
),
mainPanel(
h1("Shiny"),
p("Shiny is a package from RStudio"),
br()
)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
EDIT to Add Additional Steps Taken
When I originally posted my issue with R Shiny I was using the default R GUI. I have since switched to R Studio in case R Shiny works best that way. But this has not helped.
I have installed Rtools and added the following code to the very top of the above app.R file:
install.packages('zip')
install.packages('shinyjs')
install.packages('shinydashboard')
install.packages('shinyBS')
install.packages('shinyWidgets')
library(zip)
library(shinyjs)
library(shinydashboard)
library(shinyBS)
library(shinyWidgets)
install.packages('backports')
library(backports)
install.packages('devtools')
library(devtools)
rm(list=ls())
getwd()
setwd('C:/Users/mark_/Documents/RShiny/')
getwd()
library(shiny)
But this has not helped either.
As suggested by @MattB below I have created a subfolder named www inside the folder C:/Users/mark_/Documents/RShiny and place the file myScreenshot.png inside that www subfolder. However, this has not solved the problem. The image still does not appear.
I also tried placing the file myScreenshot.png inside that www subfolder of the RStudio folder under Program Files (C:\Program Files\RStudio\www) but this has not helped.
The image does not appear under the Open in Browser tab or under the http:// tab.
There are two options I have not yet tried. Perhaps I must change the name of the folder containing the app.R file (C:/Users/mark_/Documents/RShiny) to something other than RShiny. Perhaps that is confusing R Studio.
There is another issue that perhaps is preventing R Studio from locating the image file. When I install an R package I get the following message:
> install.packages('reshape2')
Installing package into ‘C:/Users/mark_/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘plyr’
I end up with both:
C:\Program Files\R\R-4.0.0
C:\Users\mark_\Documents\R\win-library\4.0
I wonder whether that has anything to do with R Studio not being able to locate the image file.
