I have a flexdashboard with one column and two tabsets. I want to create and plot dat2
in one tabset, and then show the data for dat2
in a second tabset. The real use case is more complex and I don't have it setup to run from global (maybe I need to figure out how to do that).
The following results in an error that dat2
cannot be located.
---
title: "test"
output:
flexdashboard::flex_dashboard:
theme: bootstrap
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
```
```{r global, include=FALSE}
set.seed(1)
dat <- data.frame(age = sample(15:99, 100, replace=TRUE),
y = runif(100))
```
Sidebar {.sidebar}
=====================================
```{r}
# age
sliderInput("agerange", label = "Age",
min = 15,
max = 99,
value = c(15, 99),
step=10)
```
Page 1
=====================================
Column {.tabset}
-----------------------------------------------------------------------
### Plot
```{r}
renderPlot({
dat2 <-
dat %>%
filter(age >= input$agerange[1] & age <= input$agerange[2]) %>%
mutate(y2 = y*2)
ggplot(dat2, aes(y2)) +
geom_histogram()
})
```
Column {.tabset}
-----------------------------------------------------------------------
### Table
```{r}
DT::renderDataTable({
DT::datatable(dat2, options = list(bPaginate = FALSE))
})
```