Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support calendar_range #363

Open
brianmsm opened this issue Apr 19, 2021 · 1 comment · May be fixed by #415
Open

Support calendar_range #363

brianmsm opened this issue Apr 19, 2021 · 1 comment · May be fixed by #415
Assignees

Comments

@brianmsm
Copy link

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.

@rszymanski rszymanski self-assigned this May 10, 2021
@esraay esraay linked a pull request Jul 6, 2022 that will close this issue
11 tasks
@esraay
Copy link
Contributor

esraay commented Jul 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants