I have a shiny app that includes MathJax equations and some script to allow for in-line equations. It works fine the RStudio IDE but not when hosted on shinyapps.io.
I have narrowed down interference to a shinymanager::secure_app()
function. It may have something to do with the head_auth
argument within secure_app()
, but I cannot figure it out.
For example:
library(shiny)
library(shinymanager)
# credentials <- data.frame(
# user = c(""),
# password = c(""),
# stringsAsFactors = FALSE
# )
ui <-
# secure_app(
fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(
tags$div(HTML(
"<script type='text/x-mathjax-config' >
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$']]}
});
</script >
")),
p(withMathJax("$$n_{\\sf larvae_0} \\sim {\\sf binomial}(n_{\\sf egg}, \\pi_{\\sf egg})$$"), style="text-align: center; font-size:20px;"),
p(withMathJax("where $n_{\\sf larvae_0}$ is the number of age-0 larvae,
$\\pi_{\\sf egg}$ is the Beverton-Holt estimated egg to larva survival probability... ")),
)
)
)
# )
server <- function(input, output) {
secure_server(check_credentials = check_credentials(credentials))
}
shinyApp(ui = ui, server = server)
returns text that includes in-line equations in both RStudio and when hosted (published) to shinyapps.io:
When I activate the secure_app()
part, the in-line text still renders properly up in RStudio IDE viewer, but DOES NOT render as an equation in the hosted app on shinyapps.io:
library(shiny)
library(shinymanager)
credentials <- data.frame(
user = c(""),
password = c(""),
stringsAsFactors = FALSE
)
ui <-
secure_app(
fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(
tags$div(HTML(
"<script type='text/x-mathjax-config' >
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$']]}
});
</script >
")),
p(withMathJax("$$n_{\\sf larvae_0} \\sim {\\sf binomial}(n_{\\sf egg}, \\pi_{\\sf egg})$$"), style="text-align: center; font-size:20px;"),
p(withMathJax("where $n_{\\sf larvae_0}$ is the number of age-0 larvae,
$\\pi_{\\sf egg}$ is the Beverton-Holt estimated egg to larva survival probability... ")),
)
)
)
)
server <- function(input, output) {
secure_server(check_credentials = check_credentials(credentials))
}
shinyApp(ui = ui, server = server)
Changing the in-line math delimiters to something other than
$
resolves the issue, although it is not clear what the conflict is with using$
. Following this answer, we can add\\( \\)
as a delimiter:Now
Results in them both working in the RStudio IDE:
But only the
\\( \\)
delimiter works once the app is published (hosted) on shinyapps.io: