Closed SL-itw closed 4 years ago
Need to use a file protocol within browsers to access a local file.
file:///Users/stevenlawrence/Desktop/cumc_github/Covid-19/Covid-19_NYC/img/zipsmap_race_caserate.png
(Would be better if the path was a relative path. But this may not be possible until hosted by shiny.)
Thank you for the quick reply.
I agree!
This has solved by initial problem but now I am getting this error which is great because at least its seeing the file. So now I need to some how allow my browser to allow this.
Ah, you already have it as a shiny application.
Use a relative path and put the image in the www
of your Shiny application directory. That will be the only way you can load file path like a relative image path.
Folder structure
app.R
www
|- img
|- zipsmap_race_caserate.png
Leaflet code
#...
addControl(
html = "<img src = 'img/zipsmap_race_caserate.png', width = '100', height = '100'>",
position = "topright",
className = "legend-bivar"
)
Thank you! The problem has been solved. I should also include that it terns out that R also stops one from accessing files in this particular way so I had to upload my image to a website I am hosting on github and then copy the image address from the page its on then it worked completely.
leaflet code
#...
addControl(
html = "<img src = 'https://sl4269.github.io/zipsmap_race_caserate.svg' width = '128' height = '128'>",
position = "topright",
className = "legend-bivar"
)
I am not sure why but now I know that having an image already hosted on another site somehow helps shiny recognize it because R won't let you access it locally for some reason.
A big thank you!
I think the addResourcePath() function from shiny can help ,if you want insert a image from you local path, just add this line command:
addResourcePath('image','../images/')
then you can just give the image url as "image/blablaXXXX" when you deploy you shiny app.
if you use golem, you can also use this command:
golem::add_resource_path('image','../images/')
When I inspect the image file it says the image is not found. However ever when I check the folder the image is there and shows when I preview it. The code is rather long so here are screen shots of where I am having the problem. The code below includes the data used for the screen shots