Hi all,
I am trying to include annotate function to my plot. So basically, as per the filtering under First variable and Second Variable, I have to calculate mean(First Variable)/mean(Second Variable). So i have included them in my code annotate("text",x=10,y=10,label = round(mean(plot_data$input$b)/mean(plot_data$input$a),2))
but I am sure there is minor mistake. But I am not able to solve this. Please guide.
Sample code below
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: scroll
runtime: shiny
theme: cosmo
---
```{r setup, include=FALSE}
library(shiny)
library(flexdashboard)
library(tidyverse)
```
```{r}
Copy_of_mill_para <- structure(list(Date = structure(c(1505779200, 1505779500, 1505779800,
1505780100, 1505780400, 1505780700, 1505781000, 1505781300, 1505781600
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), A = c(42,
40, 41, 45, 25, 39, 44, 25, 39), B = c(27, 36, 40, 31, 44, 34,
39, 44, 41), C = c(39, 42, 33, 26, 29, 42, 24, 34, 35)), row.names = c(NA,
-9L), class = "data.frame")
Copy_of_mill_para1 <- Copy_of_mill_para %>%
gather(variable, value, -Date)
```
Summary
=================
Inputs {.sidebar}
-----------------------------------------------------------------------
```{r}
selectInput("c", "Filter1", choices = c("","Correlation"))
output$filter_2 <- renderUI({
if (input$c == "") {
return()
} else {
label = "First Variable"
selectInput("b",
label,
choices = c(levels(factor(Copy_of_mill_para1$variable))))
}
})
output$filter_3 <- renderUI({
if (input$c == "") {
return()
} else {
selectInput("a",
"Second Variable",
choices = c(levels(factor(Copy_of_mill_para1$variable))))
}
})
uiOutput("filter_2")
uiOutput("filter_3")
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart A
```{r}
output$g1 <- renderPlot({
req(input$c)
if (input$c == "Correlation"){
plot_data <- Copy_of_mill_para
}
if (input$c == "Correlation") {
req(input$a)
req(input$b)
ggplot(plot_data, aes_string(x = input$b, y = input$a)) +
geom_point() + annotate("text",x=10,y=10,label = round(mean(plot_data$input$b)/mean(plot_data$input$a),2))
}
})
plotOutput("g1")
```