I'm creating a shiny app that uses the following js:
// Credits: trestletech
// https://github.com/trestletech/ShinyChat/blob/master/sendOnEnter.js
// Sending on ENTER
jQuery(document).ready(function(){
jQuery('#message_field').keypress(function(evt){
if (evt.keyCode == 13){
// Enter, simulate clicking send
jQuery('#send').click();
}
});
});
// Scrolling down
var oldContent = null;
window.setInterval(function() {
var elem = document.getElementById('chatbox');
if (oldContent != elem.innerHTML){
scrollToBottom();
}
oldContent = elem.innerHTML;
}, 300);
function scrollToBottom(){
var elem = document.getElementById('chatbox');
elem.scrollTop = elem.scrollHeight;
}
In my shiny UI i have the following code to use the js
tags$script(src = './script.js')
The problem is that if i create a module, the java script should use the id ns(chatbox)
instead of just chatbox
. Is there a way to fix this? I found this discussion, but I'm having troubles following the proposed solution.