I've created a Shiny App that filters a value on date and type.
Problem is when i want my daterangeinput to automatically update the min/max and start/end according to the type, the output happens in two steps.
I've tried to recreate a simple example (see bellow), but the problem is hard to spot as the process is very fast with so little data.
In my large App the problem is very obvious as the number is updated TWICE: first when i change the type, then after the min/max date is updated.
TLDR: How do i get my textOutput to wait outputting anything until the daterangeInput[1] and [2] is updated?
Would really appreciate some help, thanks!
SERVER.R
library(shiny)
example <- read.xlsx("example.xlsx", sheetIndex = 1, encoding = 'UTF-8')
shinyServer(function(input, output) {
# datefilter with min max
output$dates <- renderUI({
dates <- filterExample2()$date
minval <- min(dates)
maxval <- max(dates)
dateRangeInput(inputId='dates', label = "dato:",
start = minval, end = maxval,
min = minval, max = maxval,
separator = " - ")})
## date ##
filterExample <- reactive({
filter(example, date >= input$dates[1] & date <= input$dates[2])})
## type ##
filterExample2 <- reactive({
filter(example, type == input$type)})
## date & type #
filterExample3 <- reactive({
filter(example, type == input$type & date >= input$dates[1] & date <= input$dates[2])})
output$value <- renderText({
paste("total value:", as.numeric(sum(filterExample3()$value)))
})})
UI.R
shinyUI(fluidPage(
titlePanel("test!"),
sidebarLayout(
sidebarPanel(
selectInput("type", "choose type",
choices = sort(example$type),
selected = 1,
selectize = TRUE,
multiple = F)),
mainPanel(
textOutput("distPlot"),
uiOutput("dates"),
textOutput("value")
))))
DATA / EXAMPLE.XLSX
date type value
01-01-2017 A 1231
02-01-2017 A 51
03-01-2017 B 124
04-01-2017 C 2134
05-01-2017 A 214
06-01-2017 B 214
07-01-2017 B 123
08-01-2017 B 123
09-01-2017 C 124
10-01-2017 A 1
11-01-2017 A 24