---
title: "My First Shiny Dashboard"
author: "Dr. J. Adamson"
date: "`r format(Sys.time(), '%d.%m.%Y')`"
output:
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
runtime: shiny
---

# My Dashboard

```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
options(shiny.useragg=FALSE)
```


Column {.sidebar}
-------------------------------------------------------------------
```{r}
sliderInput("obs", "Number of Observations:", min=100, max=1000, value=100)
actionButton("generate", "Generate Data")
```


Column
-------------------------------------------------------------------
```{r}
data_generate <- reactive({
    input$generate
})

renderPlot({
  data_generate()
  random_obs <- runif(input$obs, 0, 1)
  hist(random_obs)
})
```



# Background {data-navmenu='Background'}

Shiny Flexdashboards combine two distinct elements. While it is possible to use Shiny without the Flexdashboard formatting, I think it is easier to remember

* `.R` files are codes for statistical analysis
* `.Rmd` files are for communicating: reports, slides, posters, and apps

## {data=width=350}

### Shiny

* https://shiny.rstudio.com/
* https://shiny.rstudio.com/articles/interactive-docs.html
* https://shiny.rstudio.com/gallery/plot-interaction-basic.html
* https://shinyserv.es/shiny/
* https://bookdown.org/egarpor/NP-UC3M/kre-i-kre.html#fig:kreg

## {data=width=350}

### Flexdashboard 

* https://pkgs.rstudio.com/flexdashboard/index.html
* https://www.paulamoraga.com/book-geospatial/sec-dashboardswithshiny.html
* https://bookdown.org/yihui/rmarkdown/shiny.html
* https://bookdown.org/yihui/rmarkdown/shiny-documents.html
* https://www.brodrigues.co/blog/2021-03-02-no_shiny_dashboard/


# PureShiny.R {data-navmenu='Background'}

Nonetheless, you can make a pure shiny app by running the following code 

```{r, eval=F, echo=T}
library(shiny)
server <- function(input, output){
    data_generate <- reactive({
        input$generate
    })    
    output$Hist <- renderPlot({
        data_generate()
        random_obs <- runif(input$obs, 0, 1)
        hist(random_obs)
    })
}
ui <- fluidPage(
    sidebarPanel(
        sliderInput("obs", "Number of Observations:", min=100, max=1000, value=100),
        actionButton("generate", "Generate Data")
    ),
    mainPanel(
        plotOutput("Hist")
   )
)
shinyApp(ui = ui, server = server)
```


<!-- ## COMPILE FROM CLI
    Rscript -e "rmarkdown::run('TrialApp1_Histogram_Dashboard.Rmd')"
-->
