在 R 中闪亮的仪表板应用程序中显示 LaTeX 方程 [英] Display LaTeX equations in a shiny dashboard app in R

查看:49
本文介绍了在 R 中闪亮的仪表板应用程序中显示 LaTeX 方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我闪亮的仪表板应用程序中显示一个带有 LaTeX 方程的 Rmd 文件.我在使用 includeMarkdown()includeHTML() 时遇到了问题.这是我试图实现的简化应用程序.这是我的应用程序.R:

I would like to display an Rmd file with LaTeX equations in my shiny dashboard app. I've run into problems using includeMarkdown() and includeHTML(). Here is a simplified app of what I'm trying to achieve. Here is my app.R:

library(shinydashboard)
ui <- dashboardPage(
    dashboardHeader(title='My test application'),
    dashboardSidebar(
        sidebarMenu(
            menuItem("Theory", tabName = "theory", icon = icon("book"))
        )
    ),
    dashboardBody(

        tabItems(

            tabItem(tabName="theory",
                    includeMarkdown("Theory.Rmd")
                    #includeMarkdown("Theory.md")
                    #includeHTML("Theory.html")
            )
        )    
    )
)

server <- function(input, output){

}

shinyApp(ui = ui, server = server)

我的 Theory.Rmd 文件:

My Theory.Rmd file:

---
title: "Theory"
output: 
  html_document:
    mathjax: "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
---
Here is an equation:

$$Q = a(h − c)^b$$ 

请注意,为了运行应用程序,Theory.Rmd 和 app.R 必须保存在同一目录(例如工作目录)中,并且必须具有这些确切名称.要获取 Rmd 文件的 Markdown Theory.md 文件,只需执行以下操作:

Note that in order to run the app, Theory.Rmd and app.R have to be saved in the same directory (e.g. the working directory) hand have to have those exact names. To obtain a markdown Theory.md file of the Rmd file, simply do:

library(knitr)
knit("Theory.Rmd","Theory.md")

要获取Theory.html 文件,只需按下 Theory.Rmd 文件中的 Knit to HTML 按钮

And to obtain the Theory.html file, simply press the Knit to HTML button in the Theory.Rmd file

在浏览器或 RStudio 窗口中运行我的应用程序时,includeMarkdown("Theory.Rmd")includeMarkdown("Theory.md"),不渲染方程,但它默认在理论菜单项中启动,如下所示:然而,使用 includeHTML("Theory.html") 方程可以正确呈现,但屏幕显示被缩短,并且默认情况下它不会在任何菜单项中启动,如下所示:

When running my app in my browser or RStudio window, includeMarkdown("Theory.Rmd") or includeMarkdown("Theory.md"), do not render the equations but it starts by default in the theory menu item, like this: However using includeHTML("Theory.html") the equations render correctly but the screen display is shortened, and by default it does not start in any menu item, like this:

但是当点击理论时,我得到了正确渲染的方程:

but when clicked on theory I get correctly rendered equations:

有没有办法解决这个问题?非常感谢!

Is there a way to fix this? Many thanks!

推荐答案

也可以将 includeMarkdown() 包裹在 withMathJax() 中,这样你就不会需要更改您的 .md-file:

It is also possible to wrap includeMarkdown() in withMathJax(), so you won't need to change your .md-file:

withMathJax(includeMarkdown("Theory.md"))

这篇关于在 R 中闪亮的仪表板应用程序中显示 LaTeX 方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆