Closed learning-freak closed 3 years ago
The image is loaded using a regular HTML img tag. You need to work out the pathing so that you can load the image is shiny as a regular img tag. If it works in img, it'll work here too.
I found the solution, we have just to put image tag inside list
object. Here the full working code :
library(shiny)
library(shinycssloaders)
ui <- fluidPage(
# Application title
titlePanel("example"),
mainPanel(
shiny::tags$img(src = "mygif.gif", height = 100, width = 100), #displayed perfectly on app
shinycssloaders::withSpinner(plotOutput("distPlot2"),
image = list(src = "mygif.gif"))
)
)
server <- function(input, output) {
output$distPlot2 <- renderPlot({
hist(rnorm(1000), main = "with my custom gif")
})
}
# Run the application
shinyApp(ui = ui, server = server)
Thank you
That's strange, you shouldn't have to use list(src=)
. You should just be able to use image = path
.
If the image is located in a www
folder or if it's used together with addResourcePath()
it should just work
I put the image in a www
folder and i used list(src=)
and its works like charm
It should work without using list src. If you have a few minutes could you upload a ZIP of a directory that contains the app along with the image file with your directory structure, where it isn't working?
Please see attachement. Its work when i use list scr
with www
folder but not when i set up like this image = C:/Users/John/Desktop/example/www/mygif.gif
or when i want to use another image file in a specific folder e.g C:/Users/John/Desktop/photos/myphoto.png
example.zip
Your example works for me using image = "mygif.gif"
. To be clear, you also need to ensure the working directory is set correctly, which means:
app.R
is locatedshiny::runApp()
or using the green "Run" button in RStudio (it won't work if you run the app by copying the code into the R console)Okay, i didn't notice that. Thank you
Hello, let assume we have an image named
mypic.gif
in a folder namedmyfolder
. how to set up image path withimage
parameter in oder to use custom image ?withSpinner(plotlyOutput("myplot"), image = "how to setup up path to custom image ?")
I tried :
withSpinner(plotlyOutput("myplot"), image = "C:/Users/john/Documents/myproject/mypic.gif")
but its doesnt work. Some help would be appreciated