0

I really need your help. I am new in R shiny and I have to use 2 reactives functions. I have a table of a DataBase which columns (id_cli, val_cli, date_cli) example (1, 12, 2020-02-01); (1,30,2020-02-02); (2, 80,2020-02-03) etc. I want to select the id_cli using the function selectInput and from there select a date range using the dateRangeInput function

This is my code :


date1 <- seq(from = min(clo$date_cli), to = max(clo$date_cli), by= "days")

tweet <- data.frame(date = date1, clo$val_cli, clo$id_cli)

selectInput(inputId="cli", label= "Choose client", choices = tweet$id_cli)

dateRangeInput(inputId ="date", label ="Choose date", start = min(tweet$date_cli)
               end = max(tweet$date_cli),
               min = min(tweet$date_cli),
               max = max(tweet$date_cli)
)


query1 <-reactive({
tweet %>%
select(id_cli, val_cli, date_cli) %>%
filer(id_cli ==input$cli)
})

query2 <-reactive ({
query1()
filter(tweet, between(date, input$date[1] input$date[2])
})

The code takes all the date range of data but does not select by id_cli which is input$cli Someone can help me please ?

Pinkette
  • 5
  • 2
  • `renderPlot({ggplot(query2(), aes(x=date, y =val_cli)) + geom_line(size=1) +xlab("date"), ylab("value") }) ` – Pinkette Sep 17 '20 at 14:26
  • Welcome to stackoverflow. It will be easier to help you if you provide a reproducible example https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – gdevaux Sep 17 '20 at 15:00
  • You also may have a misspelling: `filer(id_cli ==input$cli)` should be `filter(id_cli ==input$cli)`? – Ben Sep 17 '20 at 15:21
  • You really need to provide a reproducible example we can run. – Vikram Sep 17 '20 at 15:31
  • Yes it is `filter(id_cli ==input$cli) ` . – Pinkette Sep 17 '20 at 15:35

1 Answers1

0

query2 is reacting after query1 changes, but it's not using query1. It's still using tweet. Try:

query2 <-reactive ({
    query1() %>% between(date, input$date[1] input$date[2])
})
SmokeyShakers
  • 3,372
  • 1
  • 7
  • 18