Home > Mobile >  Shiny Title image seems unformatted
Shiny Title image seems unformatted

Time:10-11

I was working on a Shiny application, and instead of a title, I wanted to use an image. While the code did not raise any errors and shows the designated area for the image, the image doesn't show up.

Here is the code:

# header UI
ui <- navbarPage(title = div(img(src="/Users/atillacolak/Desktop/tafn_logo.png",
                                 height = 60,
                                 style = "margin-top: -14px; padding-right:10px;padding-bottom:10px")),
                 selected = "home",
                 theme = bs_theme(
                     bg = "white",
                     fg = "#ed7117",
                     base_font = font_google("Prompt"),
                     code_font = font_google("JetBrains Mono")),
                 fluid = TRUE,
                 home)

The result of this code is given in the image below.

Resulting Image

As you can see the image does not format. What is the problem here?

CodePudding user response:

You need to make the image available as a static resource to shiny's webserver.

Either you put the image in a www folder (subdirctory of your app folder) and set src = "/tafn_logo.png" or you use addResourcePath:

addResourcePath(prefix = "Desktop", directoryPath = "/Users/atillacolak/Desktop")

src using prefix:

img(src="Desktop/tafn_logo.png",
                                 height = 60,
                                 style = "margin-top: -14px; padding-right:10px;padding-bottom:10px")

See my related answer here.

  • Related