有没有办法使TableGrob和ggplot在样本输出中都具有反应性

时间:2019-10-22 08:34:50

标签: r

我确实有一些澄清。我有2个数据框。我从1个数据填充了tablegrob,从另一个数据填充了ggplot。但是有没有办法让它们反应。例如,我有一个过滤器命名(Mill-A,Mill-B等)。因此,根据此选择,我需要在“性能”选项卡中同时包含table和ggplot。我已经尽力使这种情况发生,但不幸的是,这种情况并未发生。因此,请在此社区中寻求帮助。请指导我在此处更正代码。随附示例代码

---
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")
```

0 个答案:

没有答案