'Image not rendering in Shiny Server in docker
Background
I'm using another docker image and installing Shiny Server via commands in the dockerfile. The images are in a subdirectory named "www" in the app.R directory. Below is my shiny app structure:
library(shiny)
library(shinythemes)
setwd("/srv/shiny-server/")
myFile = readRDS("MyFile.RDS")
# # Define UI
ui <- fluidPage(theme = shinytheme("readable"),
navbarPage(
title = div(img(src='logo.png',
style="margin-top: -14px;
padding-right:10px;
padding-bottom:10px",
height = 60)),
windowTitle="Sample Shiny App",
tabPanel("Tab 1", "Sample body text")
) # navbar page
) # fluid page
server <- function(input, output, session) {
# Some server code
}
shinyApp(ui = ui, server = server)
And my DockerFile is as follows:
FROM facebook/robyn
ENV TEST_ENV=""
# Shiny server app
COPY /. /srv/shiny-server/
# Install libraries
RUN Rscript /srv/shiny-server/install_packages.R
# Install Shiny Server
RUN sudo apt-get update && \
sudo apt install -y gdebi-core && \
wget https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-1.5.17.973-amd64.deb && \
sudo gdebi shiny-server-1.5.17.973-amd64.deb
EXPOSE 3838
CMD Rscript /srv/shiny-server/app.R
Problem:
The shiny app runs, it even reads the RDS file in the app directory. The only problem is that the logo.png doesn't render the way it used to do on my local simple Shiny through RStudio.
Attempts:
I've tried using different image paths, for example www/logo.png
, /srv/shiny-server/www/logo.png
, but the outcome is the same that the image doesn't render.
Question:
What can I do to get my logo image to render my logo in the Shiny Server?
Solution 1:[1]
Add this line before your ui in your R file:
shiny::addResourcePath('www', '/srv/shiny-server/www')
Then change the image path to be www/logo.png
.
If anyone else is trying to reproduce this in their Docker image, you base the resource path on how you copy your app into your image. You can use docker exec <options> <container> <command>
in your CLI to look around in the docker container for the www folder as well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |