I am currently making a dashboard to produce a dynamic plot depending on user input. I collect 3 parameters from the user: the starting date, ending date to set the time window in my plot and the specific physical site he wants to see information about. The dataset I am using is a simple csv file with dates and numeric physical data.
I'm getting the following error related to my ds() function called in the renderPlot:
object of type 'closure' is not subsettable
I thought the parenthesis would solve this but they did not, I think my ds() function does return a dataframe which should be the correct data type for the data argument in the ggplot function call but it is not. Maybe there is a problem when I wrap the ggplot call in the renderPlot function but I was not able to debug this.
I'm a bit confused
If somebody can help me I'd appreciate that.
Thanks
Here is the code
# préparation des tables (préliminaire)
dataset_stockage <- read.csv2('stock-quotidien-stockages-gaz.csv')
dataset_stockage[,2] <- as.numeric(dataset_stockage[,2])
dataset_stockage$date <- as.Date(dataset_stockage$date,format="%d/%m/%Y")
dataset_stockage <- arrange(dataset_stockage,date)
dataset_debit <- read.csv2('debit-quotidien-stockages-gaz.csv')
dataset_debit[,2] <- as.numeric(dataset_debit[,2])
dataset_impexp <- read.csv2('imports-exports-commerciaux.csv')
dataset_impexp <- dataset_impexp %>% mutate(date = str_replace_all(date, "-", "/"))
dataset_impexp$date <- as.Date(dataset_impexp$date,format="%Y/%m/%d")
dataset_impexp <- arrange(dataset_impexp,date)
```
# Stockage de gaz naturel
Column {.sidebar}
-----------------------------------------------------------------------
Selectionnez le PITS que vous souhaitez visualiser ainsi que la plage temporelle qui vous intéresse
```{r}
dataset_stockage$date <- format(dataset_stockage$date, "%Y-%m-%d")
selectInput("pit", label = "PITS à visualiser:",
choices = c(unique(dataset_stockage$pits)))
dateInput(
"startdate",
"Date de début: ",
value = min(dataset_stockage$date, na.rm = TRUE),
min = min(dataset_stockage$date, na.rm = TRUE),
max = max(dataset_stockage$date, na.rm = TRUE),
language = "fr"
)
dateInput(
"enddate",
"Date de fin: ",
value = max(dataset_stockage$date, na.rm = TRUE),
min = min(dataset_stockage$date, na.rm = TRUE),
max = max(dataset_stockage$date, na.rm = TRUE),
language = "fr"
)
```
Column
-----------------------------------------------------------------------
### Plot du niveau de stockage dans le site demandé
```{r}
ds <- reactive({dataset_stockage[dataset_stockage$pits==input$pit,] %>% ds[ds$stock_fin_de_journee<6*1000000000,] %>%
subset(ds,(date<as.Date(input$enddate)&date>as.Date(input$tartdate)))
})
renderPlot({ggplot(data=ds(),aes(x=date)) + geom_point(mapping=aes(y=stock_fin_de_journee)) +
labs(title = "Niveau de stockage (GWh PCS 0C)",
x = "Date",
y = "Stock de gaz (GWh PCS 0C)")
})
```