Friday, 2 July 2021

How to reference an image from JS file in packaged Shiny app?

I am creating an R package which provides some helper functions to build a Shiny app.

One of the JS files packaged with the app needs to reference an image file. But I can't figure out how to reference it.

Currently, the js file is located in

my_app/inst/www/js/my_jsfile.js

This file needs to reference

my_app/inst/www/img/my_img.gif

What should the relative URL in the javascript file be?

I tried various options, such as the following, which do not work, when launching in a Shiny app built with the package:

../my_img.gif

www/img/my_img.gif

My JS looks like this:

function showRecordingIcon() {

  var img = document.createElement("img");
  img.style.display = "block";
  img.src =  "img/record.gif";
  img.width = "280";
  img.height = "280";
}

This was working before I packaged it.



from How to reference an image from JS file in packaged Shiny app?

No comments:

Post a Comment