I am currently trying to develop a minimal working CustomMessageHandling dashbord in R. What I am doing is simply sending a message from my R client side to my Javascript file, which is then run in an html file. The error is as follows:
jQuery.Deferred exception: Shiny is not defined ReferenceError: Shiny is not defined
In my JavaScript file, which is called in my .html file, I simply add it at the bottom of the file, which looks like:
$(document).on('shiny:connected', function() {
console.log("Hello, I am executing!");
const clientID = "e800d12fc12c4d60960778b2bc4370af";
var urlToBase64PDF;
Shiny.addCustomMessageHandler('handler1', function()
{
doUpdate();
}
);
function base64ToArrayBuffer(base64)
{
var bin = window.atob(base64);
var len = bin.length;
var uInt8Array = new Uint8Array(len);
for (var i = 0; i < len; i++)
{
uInt8Array[i] = bin.charCodeAt(i);
}
return uInt8Array.buffer;
}
function doUpdate(message1)
{
urlToBase64PDF = message1;
}
document.write(urlToBase64PDF);
console.log(urlToBase64PDF);
document.addEventListener("adobe_dc_view_sdk.ready", function()
{
var adobeDCView = new AdobeDC.View({clientId: clientID, divId: "adobe-dc-view"});
document.write(urlToBase64PDF);
console.log(urlToBase64PDF);
adobeDCView.previewFile({content:{ promise: Promise.resolve(base64ToArrayBuffer(urlToBase64PDF))}, metaData:{fileName: "check.pdf"}},
{});
});
});
In my .html file, I call it in the following fashion:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/>
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="index.js"></script>
</head>
The rest of the functionality is built in Shiny in R, which are extremely simple UI and Server parts:
app_ui <- function() {
shiny::addResourcePath(
'www', system.file('app/www', package = 'test')
)
tags$iframe(src="www/index.html", height = 600, width = 600)
and lastly the server part:
app_server <- function(input, output, session){
shinyjs::useShinyjs()
message1 = "test"
session$sendCustomMessage("handler1", message1)
}
I have literally tried everything, searched everywhere, and even the documentation on CustomMessageHandling sends messages in the above fashion. Yet I still get the Shiny undefined Error in my console.
Edit: Exact error:
No output to console at all.
