I'm having trouble including images in a shiny app that is embedded in an R package (just getting a broken link). I've created a minimal reproducible R package on GitHub (https://github.com/mdlama/imageissue) where I've essentially embedded the Hello Shiny! example into a function hello.shiny()
and added a jpeg image. Here's the function from the package (link on GitHub):
#' Hello Shiny!
#'
#' @import shiny
#'
#' @export
hello.shiny <- function() {
ui <- fluidPage(
# Application title
titlePanel("Hello Shiny!"),
# Sidebar with a slider input for number of observations
sidebarLayout(
sidebarPanel(
sliderInput("obs",
"Number of observations:",
min = 1,
max = 1000,
value = 500)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
div(
img(src = system.file("www/img/helloworld.jpg", package="imageissue"))
)
)
)
)
server <- function(input, output) {
# Expression that generates a plot of the distribution. The expression
# is wrapped in a call to renderPlot to indicate that:
#
# 1) It is "reactive" and therefore should be automatically
# re-executed when inputs change
# 2) Its output type is a plot
#
output$distPlot <- renderPlot({
# generate an rnorm distribution and plot it
dist <- stats::rnorm(input$obs)
graphics::hist(dist)
})
}
hello.shiny.app <- shinyApp(ui = ui, server = server)
runApp(hello.shiny.app, launch.browser = TRUE)
}
I've attempted to embed an image after the plotOutput
using the following code:
div(
img(src = system.file("www/img/helloworld.jpg", package="imageissue"))
)
This was recommended by Joe Cheng on a Google Group discussion here. In that same discussion, Dean Attali recommends putting the Shiny app in the inst
directory of the package, but I'd rather not do that as the package I am developing is basically the Shiny app itself and would like to work from the R
directory where all the package code goes if possible.
I think I've done my due diligence and searched the back-alleys and armpits of the internet for solutions but couldn't find any. Any ideas? Thanks for your help!