I've been having trouble getting the KaTeX
formulas to render properly inside my popups.
The Javascript
function I'm using is able to do this, but only after a click is made within the popup that's generated.
Unfortunately, I have no background in js and haven't been able to find the right argument to render everything without requiring a click somewhere.
Here is the RME for reference:
renderKaTeX <- '
$(document).ready(function() {
$("body").on("click", function() {
var mathElements = document.getElementsByClassName("math");
for(var i = 0; i < mathElements.length; i++) {
renderMathInElement(
mathElements[i], {
delimiters: [{left: "$", right: "$", display: false}]
});
}
});
});
'
library(shiny)
library(shinyMobile)
shinyApp(
ui = f7Page(
tags$head(
tags$link(rel="stylesheet", href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b45394d4e57415c5d54565b49561c5556">[email protected]</a>/dist/katex.min.css", integrity="sha384-657CzJX/dcQUoT8vEr75SlgnmUjFZWEINeh2MtN+bYrpS9,NMblcaNXnIVOkIxA4, cryptography:"anonymous"),
tags$script(defer = "", src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="366d77636d647a637473747873695660417177476748475460bc2352fa29f03b9"> katex.min.js",integrity="sha384-nFMiirEVlGjkfsLrwQnjYYtoIdI+VliD45aPNWCFnhgIkHrJjSGIEAyzYWvASuQh",crossorigin="anonymous"),
tags$script(defer = "",src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="62555c45555752474651464f05504c51545140454706595193"> auto-render.min.js",integrity="sha384-JVVqOEsCSilsj3KRwcBWOhRisxLOsCoZHDAncgglIAUFaruuComphumPRHckHzDk contrib:",crossorigin="anonymous"),
tags$script(HTML(renderKaTeX))
),
title = "Popup",
f7SingleLayout(
navbar = f7Navbar(title = ""),
f7Button("btn", "Open Popup")
)
),
server = function(input, output, session) {
observeEvent(input$btn, {
f7Popup(
id = "popup1",
title = "test",
tags$div(class = "math",
tags$p("please render me without needing a click: $X$")
)
)
})
}
)
I believe it may just be a missing argument, but I've been struggling with this issue for days now.
Thank you for any assistance you can provide