Skip to content

Commit

Permalink
fix custom popop exemple
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Apr 29, 2024
1 parent 2997b76 commit 44c09a1
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions inst/examples/calendar-popup-shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,51 @@ ui <- fluidPage(
)

server <- function(input, output, session) {

output$cal <- renderCalendar({
calendar(view = "month", taskView = TRUE, useDetailPopup = FALSE) %>%
cal_props(cal_demo_props()) %>%
calendar(view = "month", taskView = TRUE, useDetailPopup = FALSE) %>%
cal_props(cal_demo_props()) %>%
cal_schedules(schedules) %>%
cal_events(
clickSchedule = JS(
"function(event) {",
"Shiny.setInputValue('calendar_id_click', {id: event.schedule.id, x: event.event.clientX, y: event.event.clientY});",
"function(event) {",
# "console.log(event);",
"Shiny.setInputValue('calendar_id_click', {id: event.event.id, x: event.nativeEvent.clientX, y: event.nativeEvent.clientY});",
"}"
)
)
})


observeEvent(input$calendar_id_click, {
removeUI(selector = "#custom_popup")
id <- as.numeric(input$calendar_id_click$id)
# Get the appropriate line clicked
sched <- schedules[schedules$id == id, ]

insertUI(
selector = "body",
ui = absolutePanel(
id = "custom_popup",
top = input$calendar_id_click$y,
left = input$calendar_id_click$x,
left = input$calendar_id_click$x,
draggable = FALSE,
width = "300px",
tags$div(
style = "background: #FFF; padding: 10px; box-shadow: 0px 0.2em 0.4em rgb(0, 0, 0, 0.8); border-radius: 5px;",
actionLink(
inputId = "close_calendar_panel",
label = NULL,
icon = icon("close"),
inputId = "close_calendar_panel",
label = NULL,
icon = icon("close"),
style = "position: absolute; top: 5px; right: 5px;"
),
tags$br(),
tags$div(
style = "text-align: center;",
tags$p(
"Here you can put custom", tags$b("HTML"), "elements."
),
tags$p(
"You clicked on schedule", sched$id,
"You clicked on schedule", sched$id,
"starting from", sched$start,
"ending", sched$end
),
Expand All @@ -95,23 +95,23 @@ server <- function(input, output, session) {
)
)
})

observeEvent(input$close_calendar_panel, {
removeUI(selector = "#custom_popup")
})

rv <- reactiveValues(id = NULL, status = NULL)
observeEvent(input$status, {
rv$id <- input$calendar_id_click$id
rv$status <- input$status
})

output$ui <- renderUI({
tags$div(
"Schedule", tags$b(rv$id), "has been updated with status", tags$b(rv$status)
)
})

}

shinyApp(ui, server)

0 comments on commit 44c09a1

Please sign in to comment.