0

I would like to use an image instead of the title in the navbar of my Shiny-Web-App. An example was discussed and solved in this post:
How can I insert an image into the navbar on a shiny navbarPage()

However, it does not work in my case. I can't explain why either. Here you can see my reproducible example:

library(shiny)

ui <- navbarPage(
  title = div(img(
    src = "proxy-image.png",
    height = 20,
    width = 20,
    style = "margin:1px 1px"
  ), "My title"),
  collapsible = FALSE,
  theme = bslib::bs_theme()
)

server <- function(input, output) {

}

shinyApp(ui, server)

I also added my image in the .png-format here: enter image description here

My result looks like this:

enter image description here

Can someone help me to solve my problem?
Many thanks in advance!

TobKel
  • 1,293
  • 8
  • 20
  • where is the png file relative to the app.R file? Putting the image in a `www` folder in the same directory as the R file might be the last step needed. – Andy Baxter Nov 18 '22 at 15:08
  • The png file ist in the same folder of der app.R file – TobKel Nov 18 '22 at 15:57

1 Answers1

1

Key things are to a) have your image files (and other external media such as css) in a www folder, and b) run using RStudio's 'Run App' button or using shinyAppDir(getwd()) command (to run in working directory).

So your file structure (as an RStudio project) should look like:

.
├── app.R
├── test_app.Rproj
└── www
    └── proxy-image.png
Andy Baxter
  • 5,833
  • 1
  • 8
  • 22