0
votes

I am trying to insert a logo on my shiny page.

Here is a reproducible example:

app.R file:

setwd(".../shinyApp") source("ui.R") source("server.R") shinyApp(ui, server)

I use the runApp button to run the app

ui.R file:

ui <- shinyUI(fluidPage( titlePanel("Blabla"), sidebarLayout( sidebarPanel( sliderInput(inputId="min", label="Values", min = 10, max = 100, value = 10,sep=" "), h6("Done by:"), img(src='logo.png',height=50,width=50) ), mainPanel( h1("Main title"), p("First paragraph"), h2("Subtitle"), p("Second paragraph"), tableOutput("table") ) )))

But this does not work ... I have a question mark error instead of my logo as if R could not find my image. The question mark is rightly located in my sidebarPanel though (and the text "Done by" appears).

I have put my image in a www directory since I have read in many places that it was a solution (here for ex: Image not showing in Shiny app R).

My shiny app structure is the following :

  • an app.R file:

  • a shinyApp directory containing : my ui.R, my server.R and the www directory which contains my logo.png

I have no idea what I have done wrong ... can anyone please help ? Many thanks !

1
please read and edit your question according to: How to make a great R reproducible example?pogibas
I have no idea how one can insert a slider on top of an image. Is the slider showing something?msr_003
Yes, please see my edits. The slider shows everything good except the image which does not appear... I have also tried to put the image outside the slider and it still does not work so I don't think this is the issue...Lili

1 Answers

2
votes

There are two ways to build your shiny application.

  1. Defining ui and server in a single file and name it as app.R

    library(shiny)
    ui <- shinyUI(fluidPage(
      titlePanel("Blabla"),
      sidebarLayout(
        sidebarPanel(
          sliderInput(inputId="min",
                      label="Values",
                      min = 10, max = 100, value = 10,sep=" "),
          h6("Done by:"),
          img(src='logo.png',height=50,width=50)
        )
    
      )))
    
    server <- function(input, output, session) {
      } shinyApp(ui, server)
    
  2. Defining ui and server as seperate pages and saving them as ui.R and server.R

Sample ui.R page

ui <- shinyUI(fluidPage(
  titlePanel("Blabla"),
  sidebarLayout(
    sidebarPanel(
      sliderInput(inputId="min",
                  label="Values",
                  min = 10, max = 100, value = 10,sep=" "),
      h6("Done by:"),
      img(src='logo.png',height=50,width=50)
    )

  )))

Sample server.R page

server <- function(input, output, session) {

}

Output of shiny

enter image description here