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

custom click event in v0.3 #36

Closed
dougbarrows opened this issue Aug 4, 2023 · 4 comments
Closed

custom click event in v0.3 #36

dougbarrows opened this issue Aug 4, 2023 · 4 comments

Comments

@dougbarrows
Copy link

dougbarrows commented Aug 4, 2023

Thank you for the great package! I had a question about customizing the pop up box that contains event details in version 0.3 of the package. I was using cal_events() and JS() to customize the pop up box, and this was working great in v0.2.1, but stopped working on my system in v0.3. I was following the example in this github issue. The code in the solution works for v0.2.1 and does not in v0.3 for me. Also, the example given in the cal_events help page (showing an alert when an event is clicked) doesn't work for me in v0.3, but does in v0.2.1.

This is likely something with my system (R session info is pasted below), but I was hoping you might have some ideas as to why I am having this issue. Happy to provide any additional information if helpful. Thank you so much!

Session Info:
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6.7

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] toastui_0.2.1 shiny_1.7.1 calendar_0.0.1

loaded via a namespace (and not attached):
[1] bslib_0.3.1 tidyselect_1.1.2 xfun_0.31 remotes_2.4.2 shinyjs_2.1.0 purrr_0.3.4
[7] haven_2.5.0 vctrs_0.4.1 generics_0.1.2 htmltools_0.5.2 yaml_2.3.5 utf8_1.2.2
[13] rlang_1.0.2 jquerylib_0.1.4 later_1.3.0 pillar_1.7.0 foreign_0.8-82 glue_1.6.2
[19] withr_2.5.0 DBI_1.1.3 readxl_1.4.0 lifecycle_1.0.1 cellranger_1.1.0 fontawesome_0.2.2
[25] zip_2.2.0 htmlwidgets_1.5.4 evaluate_0.15 knitr_1.39 rio_0.5.29 forcats_0.5.2
[31] fastmap_1.1.0 httpuv_1.6.5 shinyWidgets_0.7.0 curl_5.0.0 fansi_1.0.3 Rcpp_1.0.8.3
[37] xtable_1.8-4 promises_1.2.0.1 DT_0.23 cachem_1.0.6 jsonlite_1.8.0 mime_0.12
[43] hms_1.1.1 digest_0.6.29 stringi_1.7.6 openxlsx_4.2.5 dplyr_1.0.9 cli_3.3.0
[49] tools_4.1.1 sass_0.4.1 magrittr_2.0.3 tibble_3.1.7 crayon_1.5.1 pkgconfig_2.0.3
[55] ellipsis_0.3.2 data.table_1.14.2 shinydashboard_0.7.2 phosphoricons_0.2.0 assertthat_0.2.1 rmarkdown_2.14
[61] httr_1.4.3 R6_2.5.1 compiler_4.1.1

@pvictor
Copy link
Member

pvictor commented Aug 28, 2023

Hello,

Yes, there have been some changes in the JavaScript library, so it no longer works with the latest version. Here is the line to modify so that it works again:

# OLD v0.2.1
cal_events(
  clickSchedule = JS(
    "function(event) {", 
    "Shiny.setInputValue('calendar_id_click', {id: event.schedule.id, x: event.event.clientX, y: event.event.clientY});", 
    "}"
  )
)

# NEW v0.3.0
cal_events(
  clickSchedule = JS(
    "function(obj) {", 
    "Shiny.setInputValue('calendar_id_click', {id: obj.event.id, x: obj.nativeEvent.clientX, y: obj.nativeEvent.clientY});", 
    "}"
  )
)

@dougbarrows
Copy link
Author

Thank you! That is helpful and seems to work so far!

@trafficonese
Copy link

I have a similar problem. The following app worked fine with 0.2.1.
I need useCreationPopup = FALSE because I want to insert my own popup with

input$calendarId + _add

But this event doesn't seem to work anymore.

Demo ShinyApp
library(shiny)
library(toastui)
# install.packages("toastui")
# remotes::install_version("toastui", "0.2.1")
pkgv <- packageVersion("toastui")

## shiny ########
ui <- fluidPage(
  h4(paste0("Toastui: ", pkgv)),
  div("Problems with version > 0.2.1:"),
  tags$ul(tags$li("Calendar height bigger than the modal window"),
          tags$li("Adding a calendar entry doesn't work."),),
  actionButton("calender", label = "", icon=icon("calendar"))
)

server <- function(input, output, session) {
  observeEvent(input$calender, {
    showModal(modalDialog(size = "l", footer = NULL, easyClose = TRUE,
                          calendarOutput("dvfocalendar", height = "600px")
    ))
  })
  output$dvfocalendar <- renderCalendar({
    input$calender
    calendar(cal_demo_data(), view = "month", isReadOnly = FALSE, 
             navigation = TRUE,taskView = F, useCreationPopup = FALSE)
  })
  
  ## PROBLEM - This is not running with v3.0.0
  observeEvent(input$dvfocalendar_add, {
    removeUI("#calendradd")
    ui <- div(id="calendradd",
              h5(paste0("New Entry for ", as.Date(input$dvfocalendar_add$start))),
              tagAppendAttributes(textInput("caltitle", "Title", "")),
              actionButton("save","Save")
    )
    shiny::insertUI(selector = "#dvfocalendar", where = "beforeBegin",
                    ui = ui)
  })
}

shinyApp(ui, server)

@trafficonese
Copy link

trafficonese commented Sep 29, 2023

I think my problem is actually more like #8

And I think there is currently a bug in this example. I am getting;

VM34:4 Uncaught TypeError: Cannot read properties of undefined (reading 'id')

because I guess this line
Shiny.setInputValue('calendar_id_click', {id: event.schedule.id, x: event.event.clientX, y: event.event.clientY});

should be
Shiny.setInputValue('calendar_id_click', {id: event.event.id, x: event.nativeEvent.clientX, y: event.nativeEvent.clientY});

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

No branches or pull requests

3 participants