shiny.semantic icon indicating copy to clipboard operation
shiny.semantic copied to clipboard

Support calendar_range

Open brianmsm opened this issue 3 years ago • 1 comments

Hello I have tried to make a calendar_range from the calendar function, however, I can't get it to work correctly when I add the javascript code here, which allows me to do the shading and set the boundaries on each calendar.

I leave a reproduction of my example without javascript code specific:


author: brian date: 2021-04-19 output: "reprex::reprex\_document" title: loyal-rat_reprex.R

library(shiny)
library(shiny.semantic)
library(shinyjs)
library(dplyr)
library(DT)
library(nycflights13)


ui <- shinyUI(
  semanticPage(
    div(
      class="ui form",
      div(
        class="two fields",
        div(
          class="field",
          HTML("<label> Start date </label>"),
          calendar("rangestart",
                   value = lubridate::ymd("2013-02-15"),
                   min = lubridate::ymd("2013-01-01"),
                   max = lubridate::ymd("2013-09-30"))
        ),
        div(
          class="field",
          HTML("<label> End date </label>"),
          calendar("rangeend",
                   value = lubridate::ymd("2013-03-15"),
                   min = lubridate::ymd("2013-01-01"),
                   max = lubridate::ymd("2013-09-30"))
        )
      )
    ),
    segment(
      dataTableOutput("tabla1")
    )
  )
)

server <- shinyServer(function(input, output, session) {  
  new_data <- flights %>%
    mutate(
      date_new = lubridate::make_date(year, month, day)
    ) %>%
    select(date_new, dep_delay:time_hour)
  
  output$tabla1 <- renderDataTable({
    new_data %>%
      filter(date_new >= input$rangestart, date_new <= input$rangeend) %>%
      DT::datatable()
  })
  
  
})

shinyApp(ui = ui, server = server)
#> 
#> Listening on http://127.0.0.1:5956

imagen

Created on 2021-04-19 by the reprex package (v2.0.0)

Example with javascript code specific:


author: brian date: 2021-04-19 output: "reprex::reprex\_document" title: ripe-human_reprex.R

library(shiny)
library(shiny.semantic)
library(shinyjs)
library(dplyr)
library(DT)
library(nycflights13)

jsCode <- "
  $('#rangestart').calendar({
    type: 'date',
    endCalendar: $('#rangeend')
  });
  $('#rangeend').calendar({
    type: 'date',
    startCalendar: $('#rangestart')
  });
"

ui <- shinyUI(
  semanticPage(
    useShinyjs(),
    div(
      class="ui form",
      div(
        class="two fields",
        div(
          class="field",
          HTML("<label> Start date </label>"),
          calendar("rangestart",
                   value = lubridate::ymd("2013-02-15"),
                   min = lubridate::ymd("2013-01-01"),
                   max = lubridate::ymd("2013-09-30"))
        ),
        div(
          class="field",
          HTML("<label> End date </label>"),
          calendar("rangeend",
                   value = lubridate::ymd("2013-03-15"),
                   min = lubridate::ymd("2013-01-01"),
                   max = lubridate::ymd("2013-09-30"))
        )
      )
    ),
    segment(
      dataTableOutput("tabla1")
    )
  )
)

server <- shinyServer(function(input, output) {
  runjs(jsCode)

  new_data <- flights %>%
    mutate(
      date_new = lubridate::make_date(year, month, day)
    ) %>%
    select(date_new, dep_delay:time_hour)

  output$tabla1 <- renderDataTable({
    new_data %>%
      filter(date_new >= input$rangestart, date_new <= input$rangeend) %>%
      DT::datatable()
  })
})

shinyApp(ui = ui, server = server)
#> 
#> Listening on http://127.0.0.1:3441

imagen

Created on 2021-04-19 by the reprex package (v2.0.0)

The problem is that when I use the specific javascript code, the table can no longer be filtered when I change the date ranges. While when I don't use that code, it can be filtered.

brianmsm avatar Apr 19 '21 22:04 brianmsm

I fixed the maximum date problem and unresolved comments in #366 and I open a new PR #415, After reviews #366 can be closed.

esraay avatar Jul 06 '22 08:07 esraay