R闪亮中的knit2pdf:如何导出renderText

时间:2021-05-10 10:12:02

标签: r shiny latex knitr

我是 Shiny 的新手,这个问题真的让我很头疼。我制作了一个 Shiny 应用程序,您可以在其中上传 excel,设置一些变量,然后对这些变量进行一些统计测试(首先是回归模型,然后是模型假设)。我需要导出一个 pdf 文件,其中包含回归模型和统计测试的输出以及测试的结论。

我正在使用 knit2pdf,这是我的代码: 服务器:

testey=reactive({
   
   y=df_sel()[[print(input$y)]]
    
   if(input$primavar==1){
      
      probaty=adf.test(y)}
    
    else {
      if(input$primavar==2){
        
        probaty=pp.test(y)
      }
      else {
        probaty=kpss.test(y, null="Trend")
      }}
    probaty
  })

output$Conclusiony <- renderText({
    
    if(input$primavar==1 | input$primavar==2){
      if(testey()$p.value < 0.05){mensaje="We reject the null hypothesis, the variable is stationary"}else{mensaje="We keep the null hypothesis, the variable is not stationary"}
      mensaje}
    else {
      if(testey()$p.value > 0.05){mensaje="We accept the null hypothesis, the variable is stationary"}else{mensaje="We reject the null hypothesis, the  variable is not stationary"}
      mensaje}
    
    
  })
output$report = downloadHandler(
     filename = 'myreport.pdf',
  
     content = function(file) {
       out = knit2pdf('input.Rnw', clean = TRUE)
       file.rename(out, file) # move pdf to file for downloading
   },
   
     contentType = 'application/pdf'
   )

input.Rnw

\documentclass{article}

\begin{document}


<<Data>>=


# write.table(datos(),
#                   row.names = FALSE)
@

<<Stationarity>>=
print(testey())
print(Conclusiony())

@


<<Model>>=
print(Reg.model)
print(Reg.fit)
@




\end{document}

反应性函数 testey 显示在 pdf 中,但我不知道如何将 Conclusiony 打印为 pdf,这是一个 renderText。以及它如何用于 renderPlot 和 renderUi?有什么建议吗?

提前致谢:)

1 个答案:

答案 0 :(得分:0)

您可以为 Conclusiony 使用电抗导体:

Conclusiony <- reactive({
    
    if(input$primavar==1 | input$primavar==2){
      if(testey()$p.value < 0.05){mensaje="We reject the null hypothesis, the variable is stationary"}else{mensaje="We keep the null hypothesis, the variable is not stationary"}
      mensaje}
    else {
      if(testey()$p.value > 0.05){mensaje="We accept the null hypothesis, the variable is stationary"}else{mensaje="We reject the null hypothesis, the  variable is not stationary"}
      mensaje}
  })

output$Conclusiony <- renderText({
  Conclusiony()
})
相关问题