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.
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)Defining ui and server as seperate pages and saving them as
ui.R
andserver.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
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
How to Resolve Spherical Geometry Failures When Joining Spatial Data
Relocating Alaska and Hawaii on Thematic Map of the Usa with Ggplot2
Select Na in a Data.Table in R
Using Un-Exported Function from Another R Package
Buffer (Geo)Spatial Points in R with Gbuffer
Wrap Text Around Plots in Markdown
How to Conditionally Highlight Points in Ggplot2 Facet Plots - Mapping Color to Column
How to Use Empty Space Produced by Facet_Wrap
Output in R, Avoid Writing "[1]"
Find Out the Number of Days of a Month in R
How to Use Dplyr's Summarize and Which() to Lookup Min/Max Values
Merge Dataframes, Different Lengths
Combining S4 and S3 Methods in a Single Function
Edit Datatable in Shiny with Dropdown Selection for Factor Variables
Compute Monthly Averages from Daily Data
R: Ggplot Stacked Bar Chart with Counts on Y Axis But Percentage as Label