结合闪亮的应用程序和 Rmd 文件

Combining Shiny app and Rmd file

我在 R 中有一个 RMD 文件,我在这个文件中使用闪亮的应用程序来读取 csv 文件并对数据进行一些清理。然后我需要访问 Rmd 文件中的这些数据,只有在完成清理后,Rmd 的剩余部分才会被处理!

我的建议:

---
title: "Report_HTML"
author: "Mohammad"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: html_document
runtime: shiny
---

## Read file
This report...... (some text)

```{r, echo=FALSE}
library(tcltk)
inputPanel(
  checkboxInput('header', 'Header', FALSE),
  radioButtons('sep', 'Separator',
               c(Comma=',',
                 Semicolon=';',
                 Tab='\t'),
               ';'),
  radioButtons('quote', 'Quote',
               c(None='',
                 'Double Quote'='"',
                 'Single Quote'="'"),
               '"'),
  fileInput('file1', 'Choose a file to upload',
            accept = c(
              'text/csv',
              'text/comma-separated-values',
              'text/tab-separated-values',
              'text/plain',
              '.csv',
              '.tsv'
            )
  )
)

remove.duplicates <- function(dt){
   #some data cleaning
   return(dt)
}

datasetInput <- reactive({

  inFile <- input$file1

  dt <- read.csv(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote)

  #Remove duplicates
  dt2 <- remove.duplicates(dt)

  dt2

})

renderDataTable({
  datasetInput()
})
```

## Statistics
in this section I need to add some simple statistics like min, max, mean for each column of the `dt`.
```{r, echo=FALSE}
code for calculating min, max, and mean each column dt and show them in a table
```

我有两个问题:

  1. 我只想 运行 之后与统计部分相关的代码 读取和清理数据不是加载 Rmd 的开始 文件。
  2. 我无法访问“统计信息”部分中的 dt,如何 我可以访问吗?

感谢您的帮助

我使用 中解释的方法解决了这个问题。希望对遇到同样问题的人有所帮助