首页 > 解决方案 > 在 rMarkdown 中上传文件并调用文件生成统计摘要

问题描述

我是新手,正在尝试学习 R,我制作了一个应用程序,您可以在其中上传 file.csv,但我不知道如何调用数据以生成摘要、绘图等。我将感谢您帮助理解如何进行的系统方法。代码附在下面。提前致谢。代码如下:

---
title: "Data Visualization"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: scroll
    #storyboard: true
runtime: shiny
---

```{r setup, include=FALSE}

library(flexdashboard)
library(shiny)
library(shinyWidgets)
library(DT)
library(formattable)
library(Hmisc)
library(tidyverse)
library(plotly)
library(ggplot2)
```

Sidebar {.sidebar}
=====================================================

```{r}
fileInput('file1', 'Choose a file to upload',
        accept = c(
          'text/csv',
          'text/comma-separated-values',
          'text/tab-separated-values',
          'text/plain',
          '.csv',
          '.tsv')
        )

```

Page 1
=========================================================

Column {data-width=350}
------------------------------------------------------------

### Dataset

```{r}
rv <- reactiveValues(data = NULL)

observe( {
  req(input$file1)

  inFile <- input$file1
  data2 <- read.csv(inFile$datapath, stringsAsFactors=FALSE)
  save(data2, file = "dataread.RData")

  rv$data <- data2
})

DT::renderDataTable({
  req(rv$data)
  rv$data
})
```

------------------------------------------------------------

### Data Summary

```{r}

summary(???)

#how to call the data, if PLOT, is it:

#plot(inFile$file) # In the code chunk it also called: 
#data2 <-     read.csv(inFile$datapath, #stringsAsFactors=FALSE) 
#if I write plot(data2),     it doesn't generate a plot, neither for summary.
```

标签: shinyrstudior-markdownflexdashboard

解决方案


推荐阅读