Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Including JS in Shiny module

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!