Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将rmarkdown渲染为字符变量_R_Shiny_R Markdown - Fatal编程技术网

将rmarkdown渲染为字符变量

将rmarkdown渲染为字符变量,r,shiny,r-markdown,R,Shiny,R Markdown,我对R markdown相当陌生。我已经建立了一个应用程序,要求用户提供多个输入来生成一个表,然后可以保存在本地。 现在,我被要求实现一种报告,列出用户插入的所有变量(在一种格式化文档中),这样在生成表之前,可以查看所有设置,并在出现错误时进行更改 为了避免主要的UI重构,我考虑使用r标记文档,并将其可视化到模式中。我的问题是rmarkdown::render呈现到输出,而bs_modal将字符(HTML)变量作为参数体。 有没有办法让这一切顺利进行?还是有更好的方法来实现这一点 一个简单的例子

我对R markdown相当陌生。我已经建立了一个应用程序,要求用户提供多个输入来生成一个表,然后可以保存在本地。 现在,我被要求实现一种报告,列出用户插入的所有变量(在一种格式化文档中),这样在生成表之前,可以查看所有设置,并在出现错误时进行更改

为了避免主要的UI重构,我考虑使用r标记文档,并将其可视化到模式中。我的问题是
rmarkdown::render
呈现到输出,而
bs_modal
将字符(HTML)变量作为参数体。 有没有办法让这一切顺利进行?还是有更好的方法来实现这一点

一个简单的例子:

我的.Rmd

---
title: "Dynamic report"
output:
  html_document: default
  pdf_document: default
params:
  n : NA
---

A plot of `r params$n` random points.

```{r, echo=FALSE}
plot(rnorm(params$n), rnorm(params$n))
```
我的App.R

library(shiny)
library(bsplus)
library(rmarkdown)

shinyApp(
  ui = fluidPage(
    selectInput(
      inputId = "numb",
      label = "Label with modal help",
      choices = 50:100
    ),
    actionButton(inputId = "mysheet",
                 label = "Open modal") %>%  bs_attach_modal(id_modal = "modal1"),
    textOutput("result")
  ),
  server = function(input, output) {
    observeEvent(input$mysheet, {
      params <- input$numb
      md_out <-
        rmarkdown::render(
          "report.Rmd",
          params = params,
          envir = new.env(parent = globalenv())
        )
      bs_modal(
        id = "modal1",
        title = "Equations",
        body = md_out,
        size = "medium"
      )
      
    })
    output$result <- renderText({
      paste("You chose:", input$numb)
    })
  }
)
库(闪亮)
图书馆(bsplus)
图书馆(rmarkdown)
shinyApp(
ui=fluidPage(
选择输入(
inputId=“numb”,
label=“带模式帮助的标签”,
选择=50:100
),
actionButton(inputId=“mysheet”,
label=“Open model”)%%>%bs\u attach\u model(id\u model=“modal1”),
文本输出(“结果”)
),
服务器=功能(输入、输出){
observeEvent(输入$mysheet{

params
bs_model
不是这样工作的,它必须在UI中。下面是一个使用经典闪亮model、no
bsplus
或其他软件包的解决方案

library(shiny)

shinyApp(
  ui = fluidPage(
    selectInput(
      inputId = "numb",
      label = "Label with modal help",
      choices = 50:100
    ),
    actionButton(inputId = "mysheet",
                 label = "Open modal"),
    textOutput("result")
  ),
  server = function(input, output) {
    observeEvent(input$mysheet, {
      params <- list(n = input$numb)
      md_out <-
        rmarkdown::render(
          "report.Rmd",
          params = params,
          envir = new.env(parent = globalenv())
        )
      showModal(modalDialog(
        includeHTML(md_out),
        title = "Equations",
        size = "m"
      ))
      
    })
    output$result <- renderText({
      paste("You chose:", input$numb)
    })
  }
)

bs_model
不是这样工作的,它必须在UI中。下面是一个使用经典闪亮model、no
bsplus
或其他软件包的解决方案

library(shiny)

shinyApp(
  ui = fluidPage(
    selectInput(
      inputId = "numb",
      label = "Label with modal help",
      choices = 50:100
    ),
    actionButton(inputId = "mysheet",
                 label = "Open modal"),
    textOutput("result")
  ),
  server = function(input, output) {
    observeEvent(input$mysheet, {
      params <- list(n = input$numb)
      md_out <-
        rmarkdown::render(
          "report.Rmd",
          params = params,
          envir = new.env(parent = globalenv())
        )
      showModal(modalDialog(
        includeHTML(md_out),
        title = "Equations",
        size = "m"
      ))
      
    })
    output$result <- renderText({
      paste("You chose:", input$numb)
    })
  }
)