Hi Experts here. I do have some clarification. I have 2 dataframes. I have populated tablegrob from 1 data and ggplot from another data. But is there a way to make them reactive. For example, I have a filter naming (Mill-A, Mill-B and so on). So as per this selection , I need to have both table and ggplot in Performance tab. I have tried myself to make this happen but unfortunately it did not happen, So asking help in this community here. Please guide me in correcting the code here. Sample code attached
---
title: "Untitled"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
theme: cosmo
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(ggplot2)
library(shiny)
library(RGraphics)
library(gridExtra)
```
```{r}
Performance1 <- structure(list(Mills = c("Mill-A", "Mill-B", "Mill-C", "Mill-D",
"Mill-E"), Performance = c(0.5, 0.4, 0.2, 0.9, 0.4)), row.names = c(NA,
-5L), class = "data.frame")
Past_Maintainence <- structure(list(Mill = c("Mill-A", "Mill-B"), `Electrical Maintainence done` = structure(c(1569283200,
1569369600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
`Instrumentation Maintainence done` = structure(c(1569369600,
1569456000), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
`Mechanical Maintainence done` = structure(c(1569456000,
1569283200), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(NA,
-2L), class = "data.frame")
```
Summary
=================
Inputs {.sidebar}
-----------------------------------------------------------------------
```{r}
selectInput("Mill1","Equipment",choices = c("All","Mill-A","Mill-B","Mill-C","Mill-D","Mill-E"),selected = "All",multiple = TRUE)
```
Column {data-width=300}
-----------------------------------------------------------------------
### Performance {data-width=10}
```{r}
output$t31 <- renderPlot({
if (input$Mill1 != "All"){
pd1 <- Past_Maintainence %>% filter(Mill %in% input$Mill)
}
if (input$Mill1 != "All"){
tableGrob(pd1,theme = ttheme_default(base_size = 8))
}
})
output$g34 <- renderPlot({
if (input$Mill != "All") {
pd <- Performance1 %>% filter(Mills %in% input$Mill)}
if (input$Mill != "All") {
ggplot(data = pd,aes(x=Mills,y=Performance, fill=Performance))+geom_bar(stat = "identity",width = 0.5)+theme(plot.margin = unit(c(1,1,1,1),"cm"))+theme(axis.title.x = element_blank())+theme(axis.title.y = element_blank())+theme(legend.position = "none")+theme(axis.text.x = element_text(angle = 0,vjust = 1,size = 5))+theme(axis.text.y = element_text(angle = 0,vjust = 1,size = 5))
}
})
grid_layout <- rbind(c(1, 2))
output$filter_71 <- renderUI(
if (input$Mill1 != "All") {
plotOutput("t31")
plotOutput("g34")
})
uiOutput("filter_71")
```