R有光泽:交互式渲染LaTeX

时间:2014-08-08 13:22:52

标签: r latex shiny

在R闪亮中使用LaTeX我发现此提示How to output good-looking matrix很有帮助。 (抱歉,我的知识和声誉太短,无法在那里发表评论。) 但至少对我而言,它并不是以交互方式工作的。我找到了一个解决方案来获得漂亮的外观。但我得到原始的LaTeX代码,好像我直接运行Stefanies的例子。 这是我的代码

library(shiny)
library(xtable)
if (!exists("dummy.output")) dummy.output <- NULL
ui <- 
  shinyUI(pageWithSidebar(

    # Application title
    headerPanel(
      HTML("App with $\\int \\alpha^2 $ und $$\\beta/3 $$")),
    # Sidebar with a slider input for number of observations
    sidebarPanel(
      tags$head( tags$script(src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full", type = 'text/javascript'),
                 tags$script(src = 'https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML', type = 'text/javascript'),
                 tags$script( "MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});", type='text/x-mathjax-config')
      ),
      sliderInput(
        inputId = "n",label = HTML("Dimension $ \\beta $"),
        value = 5,min = 3,max = 7,step = 1)
    ),
    # Show a plot of the generated distribution
    mainPanel(
      HTML("$\\alpha$ und $\\Omega$"),
      uiOutput("test.html"), 
      uiOutput("matrix.raw"), 
      #uiOutput("matrix.nicer"),#ging nicht
      p(br()),
      uiOutput("matrix.nicer"),
      p(br()),
      p("doesn' work, so brutal work with dummy.output made matrix ",
        "nice but then without intereactivity"),
      HTML(dummy.output),
      HTML("End.$\\clubsuit$")
    )
  ))

server <- function(input,output){
  output$test.html <- renderPlot({plot(rnorm(50))})
  mk.matrix <- reactive({
    n <- input$n
    x <- (5:(4+n^2))/4
    mm <- matrix(x^2,nrow = n)
    rownames(mm) <- letters[1:n]
    return(mm)
  })
  output$matrix.raw <- renderTable({mk.matrix()})  
  output$matrix.nicer <- renderUI({
    mm <- mk.matrix()
    mm <- print(
      xtable(mm, align=rep("c", ncol(mm)+1)), 
      floating=FALSE, tabular.environment="array", 
      comment=FALSE, print.results=FALSE)
    xx <- paste0("$$", mm, "$$") 
    dummy.output <<- xx
    return(xx)
  })
}

runApp(list(ui=ui,server=server))

标题和文字中的所有符号都很酷。所以我相信我的交互设置有问题。

0 个答案:

没有答案