Image Not Showing in Shiny App R

Image not showing in Shiny app R

After coming back to this problem, I found that the solution is to simply format the Shiny code properly, by naming the R file app.R, and clicking Run App as opposed to selecting all of the code and running within the console.

Not sure how or why this makes a difference, but the numerous Shiny applications I have worked on since have all been resolved when doing this.

R shiny - image does not appear

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

Sample Image

Image failing to display in R shiny

Have you checked this answer? Embedding Image in Shiny App

Maybe rewrite the titlePanel to:

titlePanel(title=div(id="dummy", img(height = 100,
width = 100,
src = "dummy-logo.png"))),

And check if the image is really named - dummy-logo.png.

Otherwise i would suggest you create a New Project in RStudio -> New Directory -> Shiny Web Application. Put your ui and server functions in there.
Create the www-folder, put your image in there and it should work like that.

Not able to see image in shiny

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"))
)

Display locally-stored image in R Shiny

For me the following also works when running the app via Run Selected Line(s) in RStudio:

library(shiny)

# create some local images
if(!dir.exists("myimages")){
dir.create("myimages")
}

myPlotPaths <- paste0("myimages/myplot", seq_len(3), ".png")

for (myPlot in myPlotPaths) {
png(file = myPlot, bg = "transparent")
plot(runif(10))
dev.off()
}

myImgResources <- paste0("imgResources/myplot", seq_len(3), ".png")

# Add directory of static resources to Shiny's web server
addResourcePath(prefix = "imgResources", directoryPath = "myimages")

ui <- fluidPage(
tags$img(src = myImgResources[1], width = "400px", height = "400px"),
tags$img(src = myImgResources[2], width = "400px", height = "400px"),
tags$img(src = myImgResources[3], width = "400px", height = "400px")
)

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

}

shinyApp(ui, server)


Related Topics



Leave a reply



Submit