all.
I have JS code that works in a Shiny App but no longer works when I call it in a module. I assume this problem has to do with name spaces, but I'm at a loss. Help would be greatly appreciated.
Works when not in a module:
actionButton('download_try_2', "Download Plot"),
mainPanel(plotlyOutput("wv_test", height = "650"),
tags$script('document.getElementById("download_try_2").onclick = function() {
var gd = document.getElementById("wv_test");
Plotly.Snapshot.toImage(gd, {format: "png"}).once("success", function(url) {
var a = window.document.createElement("a");
a.href = url;
a.type = "image/png";
a.download = "plot.png";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
} ')
When I try:
actionButton(NS(id, 'download_try_2'), "Download Plot"),
mainPanel(plotlyOutput(NS(id, "wv_test")),
tags$script('document.getElementById("wv_test-download_try_2").onclick = function() {
var gd = document.getElementById("wv_test-wv_test");
Plotly.Snapshot.toImage(gd, {format: "png"}).once("success", function(url) {
var a = window.document.createElement("a");
a.href = url;
a.type = "image/png";
a.download = "plot.png";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
} ')
I get the error:
Error in htmltools::validateCssUnit(width) : CSS units must be a single-element numeric or character vector