Search code examples
rshinysrc

Not able to see image in shiny


This is a basic practice question in http://shiny.rstudio.com/tutorial/written-tutorial/lesson2/ and the answer also seems to match upto a certain point but when the app is run the photo is not shown even if in the working directory. Could somebody please help.

library(shiny)

# Define UI
ui <- fluidPage(
titlePanel(strong("My shiny app"), windowTitle = "My first"),

sidebarLayout(sidebarPanel(

   h1(strong("Installation")),
   p("Shiny is available on CRAN, so you can install it in the usual way from your R console:"),
   p(code('install.package("shiny")')),
   br(),
   br(),
   br(),
   br(),
   img(src = "rstudio.png", height = 70, width = 200)
                                 )
   mainPanel("main panel"))
    )

# Define server logic
server <- function(input, output) {


    }

# Run the application 
shinyApp(ui = ui, server = server)

The answer shown on the answer can be seen with the help of reveal answer below the image. Image path:- http://shiny.rstudio.com/tutorial/written-tutorial/lesson2/images/my-shiny-app.png

I am still learning so the whole code has not bee written and i have no separate www/ directory as this is just for learning process. Not creating a logo or something as in the other similar question. This is just upto the image addition point.


Solution

  • You have error in code.
    Add full path to the file. Sometimes Rstudio-viewer didn't show images. But you always can open app into browser.

    ui <- fluidPage(
      titlePanel(strong("My shiny app"), windowTitle = "My first"),
    
      sidebarLayout(sidebarPanel(
    
        h1(strong("Installation")),
        p("Shiny is available on CRAN, so you can install it in the usual way from your R console:"),
        p(code('install.package("shiny")')),
        br(),
        br(),
        br(),
        br(),
        img(src = "http://shiny.rstudio.com/tutorial/written-tutorial/lesson2/images/my-shiny-app.png", height = 70, width = 200)
      ),
      mainPanel("main panel"))
    )