Search code examples
rshinyflexdashboard

second page does't get updated when using sidebar


I want to have a sidebar in each page.

I don't want to use a sidebar for all pages because for some pages I don't want it.

That's why I am using Inputs {.sidebar} and Outputs.

But, the problem is that in the Second page the sidebar is not reactive. If I change the date range the plot isn't updated as in the first page Intro.

---
title: "Untitled"
author: "George"
date: "12/3/2018"
output:
    flexdashboard::flex_dashboard
runtime: shiny
---

```{r global, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(flexdashboard)
library(dplyr)
library(lubridate)
library(ggplot2)


dates <- c("01/01/18 1:00:00 PM" ,"01/01/18 1:01:00 PM",
           "01/01/18 1:02:00 PM" ,"01/01/18 1:03:00 PM",
           "01/01/18 1:04:00 PM" ,"01/01/18 1:05:00 PM",
           "02/01/18 1:00:00 PM" , "02/01/18 1:10:00 PM",
           "03/01/18 1:06:00 PM" ,"03/01/18 1:07:00 PM",
           "03/01/18 1:08:00 PM" ,"03/01/18 1:09:00 PM",
           "03/01/18 1:10:00 PM" ,"03/01/18 1:11:00 PM")

x <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
y <- c(11,22,33,44,55,66,77,88,99,100,111,112,113,114)

datfr <- data.frame(dates, x, y)

datfr$dates <- dmy_hms(datfr$dates)
```

Intro
========================================================================

Inputs {.sidebar}
--------------------------------------------------------------------
```{r}
dateRangeInput('dateSelect', 'Date Range', start = min(datfr$dates),
               end = "2018-01-03", min = min(datfr$dates),
               max = max(datfr$dates))
dateRange <- reactive({
  datfr %>%
  filter(dates >= input$dateSelect[1] & dates <= input$dateSelect[2])
})
```

Outputs
-----------------------------------------------------------------------

### Chart


```{r}
renderPlot({
  ggplot(dateRange(), aes(x, y)) +
    geom_point()
})

```

Column
------------------------------------------------------------

Hi thgere


Second
====================================================

Inputs {.sidebar}
--------------------------------------------------------------------
```{r}


dateRangeInput('dateSelect', 'Date Range', start = min(datfr$dates),
               end = "2018-01-03", min = min(datfr$dates),
               max = max(datfr$dates))

```


Outputs
-------------------------------------------------------------------


### Here

```{r}

df_by_day <- datfr %>%
    dplyr::mutate(
        new_x = (x + 10),
        new_y = (y + 20),
    )


dateRange2 <- reactive({
  df_by_day %>%
  filter(dates >= input$dateSelect[1] & dates <= input$dateSelect[2])
})


renderPlot({

ggplot(dateRange2(), aes(x, y)) +
  geom_point()

})
```


Don't want sidebar here
==================================================

NO

Solution

  • Input identifiers must be unique.

    You could rename the second dateRangeInput() as 'dateSelect2' and use it accordingly in dateRange2 <- reactive({ ... ; input$dateSelect2 ; ... }).