---
title: "Summary Statistics"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,error = FALSE, warning = FALSE)
library(shiny)
library(pastecs)
library(ggpubr)
library(rmarkdown)
library(knitr)
library(kableExtra)
library(magrittr)
library(summarytools)
library(dplyr)
```
```{r echo=FALSE, error=FALSE, message=FALSE, warning=FALSE, include=TRUE,warn.conflicts=FALSE}

csvfile = reactive({
  csvfile = input$file1
  if (is.null(csvfile)) {
    return(NULL)
  }
  dt = read.csv(csvfile$datapath, header = input$header, sep = ",",check.names = FALSE)
})
# output
if (input$req == "summary") {
  if (input$submit4 > 0) {
    y = subset(csvfile(), select = input$var)
    final =
      summarytools::descr(y) %>%
      summarytools::tb(order = 3) %>%
      knitr::kable(digits = 2, caption = "Summary Statistics") %>%
      kableExtra::kable_styling("bordered", full_width = F) %>%
      kableExtra::collapse_rows(columns = 1, valign = "top")
    final
  }
}

if (input$req == "sumbygrp") {
  if (input$submit5 > 0) {
    y1 = subset(csvfile(), select = input$var)
    y2 = subset(csvfile(), select = input$group)
    final =
      summarytools::stby(y1, y2, descr) %>%
      summarytools::tb(order = 1) %>%
      knitr::kable(digits = 2, caption = "Summary Statistics by Group") %>%
      kableExtra::kable_styling("bordered", full_width = F) %>%
      kableExtra::collapse_rows(columns = 1, valign = "top")
    final
  }
}
```


**package: grapesAgri1, Version 1.0.0**



