【问题标题】:knit2pdf in R shiny: how to export renderTextR闪亮中的knit2pdf:如何导出renderText
【发布时间】:2021-07-31 17:57:38
【问题描述】:

我是 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'
   )

输入.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 工作的?有什么建议吗?

提前致谢:)

【问题讨论】:

    标签: r shiny latex knitr


    【解决方案1】:

    您可以为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()
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      • 1970-01-01
      • 2020-12-22
      • 1970-01-01
      • 2020-01-14
      相关资源
      最近更新 更多