3

I would like to change the directory where shiny takes the images from. I need to put the www folder with the logo.jpg inside another folder called additional_files as a requirement for my homework task. I've read the documentation but I don't understand it since this is my very first R project. How do I choose the prefix and directoryPath argument such that shiny goes through my wanted files? I also need it to work in any desktop not just mine. I've seen some examples where the directoryPath has the form C:\User... I need it to work from the workingdirectory I've set. This was my attemp but it throws an error message regarding unused arguments:

ui <- dashboardPage(
    skin = "green",
    addResourcePath(prefix = "logo_fach_qual.jpg", directoryPath = "Additional_Files_Group_01/www"),
    box(img(src = "logo_fach_qual", width = "50%", height = "50%")),
    dashboardHeader(title = "Case Study 01"),

    dashboardSidebar(collapsed = TRUE,
      sidebarMenu(
        menuItem("Production Volume", tabName = "production"),
        menuItem("Error rate of parts and components", tabName = "error"),
        menuItem("Logistic network", tabName = "network"))))

The logo is supposed to appear on the top right corner. Thank you very much in advance.

sacchh
  • 37
  • 4

1 Answers1

2

addResourcePath maps the content of a folder to a path of the URL, using its 2 parameters:

  • prefix is the path
  • directoryPath is the subfolder

To set Shiny to serve files from the "images" subfolder of your shiny app, and map it to a "pics" subpath of your app URL, use:

addResourcePath(prefix = "pics", directoryPath = "images")

In a your app, to reference an image called "my_pic.jpg" that sits in that "images" subfolder, use:

img(src="pics/py_pic.jpg")
HubertL
  • 19,246
  • 3
  • 32
  • 51