-
Notifications
You must be signed in to change notification settings - Fork 8
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
Popup customization #8
Comments
Hello, It might be difficult to add Shiny input widget or sophisticated elements in the built-in pop-up, a solution can be to use Shiny's logic with # Calendar: custom popup --------------------------------------------------
library(shiny)
library(toastui)
## Schedules data
schedules <- cal_demo_data()
# add an id
schedules$id <- seq_len(nrow(schedules))
# add custom data in "raw" attribute
schedules$raw <- lapply(
X = seq_len(nrow(schedules)),
FUN = function(i) {
list(
status = sample(c("Completed", "In progress", "Closed"), 1)
)
}
)
## App
ui <- fluidPage(
fluidRow(
column(
width = 8, offset = 2,
tags$h2("Custom popup made with Shiny"),
calendarOutput(outputId = "cal"),
uiOutput("ui")
)
)
)
server <- function(input, output, session) {
output$cal <- renderCalendar({
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});",
"}"
)
)
})
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,
draggable = FALSE,
width = "300px",
tags$div(
style = "width: 250px; position: relative; 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"),
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,
"starting from", sched$start,
"ending", sched$end
),
tags$b("Current status:"), tags$span(class = "label label-primary", sched$raw[[1]]$status),
radioButtons(
inputId = "status",
label = "New status:",
choices = c("Completed", "In progress", "Closed"),
selected = sched$raw[[1]]$status
)
)
)
)
)
})
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) let me know if you have any questions about the above code Victor |
Really smooth!!! Thank you so much Victor. I was not aware of the |
Just came from the documentation to your Github repo to see whether one can select a date on the monthly calendar and get a menu to enter data for that specific date (or a date range starting from that date). From what I read here, this seems possible, correct? It would be amazing if you would include this as a feature! |
@januz yes you can interactively add schedules in a calendar, but it will only work in Shiny since you need a backend to save data. |
This work well when the schedule is already created. However, the event is not triggered when creating a new schedule by clicking on some other part of the calendar. For example, "clickSchedule" is triggered when clicking on the schedules with blue background but not when defining a new period (see period defined on Wednesday in the above image). I looked at "beforeCreateEvent" which seems to be the relevant event but I am not sure how to redefine it (I am JS/htmlwidget newbie). Accessorily, let me state some reasons why I want to do that in case I should use a different approach:
UPDATE Looking at your example I see that there are shiny events that I could use:
I am still exploring it (are these events documented? why use cal_proxy_xxxx?) |
Hello @gavril0 , |
@gavril0 did you figure this out? I would also like to create a custom pop-up for new events, but I don't see any examples of how to do this (calendar-popup-shiny.R just works for existing events... after applying the bugfix for v0.3). |
@gavril0 at least for me, |
@nick-youngblut I ended up not using pop-up. However, I have to go back to the issue because I need to update my |
Hello @nick-youngblut, can you provide an exemple to reproduce the issue ? |
@pvictor I have 2 issues:
I need a custom pop-up for both creating new events and updating existing events, because I need to include 2 drop-downs in the pop-up that the user MUST select when creating an event. This is why I cannot simply use Google Calendar, since one cannot add mandatory drop-downs for creating events. If you could point me to any documentation/examples, or provide some here, I'd appreciate it. I'm using toastui v0.3. |
For the first issue, you can try this example : https://github.com/dreamRs/toastui/blob/master/inst/examples/calendar-custom-create.R, note that you need last GitHub version where I added support for selectdatetime event. For the second one,, you should be able to do something like this with your own infos about the schedule to update : library(shiny)
library(toastui)
library(lubridate)
ui <- fluidPage(
tags$h2("Update schedule"),
actionButton("update", "Update"),
calendarOutput(outputId = "cal")
)
server <- function(input, output, session) {
output$cal <- renderCalendar({
calendar() %>%
cal_schedules(
id = "MY_CUSTOM_SCHEDULE_ID",
calendarId = "MY_CUSTOM_CALENDAR_ID",
title = "Title",
body = "Some description",
start = Sys.Date(),
end = Sys.Date(),
category = "allday"
)
})
observeEvent(input$update, {
date <- Sys.Date() + sample(-10:10, 1)
cal_proxy_update(
"cal",
list(
id = "MY_CUSTOM_SCHEDULE_ID",
calendarId = "MY_CUSTOM_CALENDAR_ID",
title = sample(ls(pos = "package:base"), 1),
start = date,
end = date
)
)
})
}
shinyApp(ui, server) |
Thanks @pvictor for the detailed response! I haven't tried the 1st issue solution yet, but the for 2nd, What is actually needed for the $schedule
$schedule$id
[1] "shd_ec425d5b"
$schedule$title
[1] "test"
$schedule$location
[1] "test"
$schedule$start
[1] "2024-01-30T00:00:00-08:00"
$schedule$end
[1] "2024-01-30T00:00:00-08:00"
$schedule$isAllday
[1] FALSE
$schedule$category
[1] "time"
$schedule$calendarId
[1] "clnd_00c2cdbf"
$changes
$changes$title
[1] "test1" Based on the cal_proxy_update code, it appears that I need to provide:
I've tried this:
However, this input to UPDATE: I see that I have to use |
the example I provided doesn't work for you?
You already have that since you called |
A challenge for me in creating a custom pop-up allowing for schedule editing was that I not only had to figure out what data structure to provide as the The pop-up for schedule editing seems to be correctly working fully. Thanks for all of your help. I was also able to create a custom pop-up for creating new events (after updating the package to the latest version on github). Will you be releasing a new version on CRAN soon, or are you waiting on some more updates first? Thanks! 🙏 |
@pvictor in the calendar-custom-create.R example, you use Is there a way to create a custom pop-up for creating an event at the location on the calendar (e.g., day) were the user clicks? |
It's certainly possible, but I find it hard to see the added value compared to the complexity it would require to implement. The modal solution seems simple, robust and immediately available. |
After trying out the modal solution, I agree... especially given that one can obtain the date/time info from where the user clicks on the calendar to fill in date/time info in the modal. |
How can I add namespaces to javascript in calendar-custom-create.R, if you know, thank you very much! |
@pvictor after I add a new event, the event cannot be selected via my custom pop-up code for editing (no value for the new event in I'm using Any ideas on why Note: it appears that calendar-custom-create.R also does not update |
@nick-youngblut , @toxintoxin : can you please open new issues with some reproducible example ? |
Hi,
Is there any way to customize the
calendar()
popup with different user inputs whenisReadOnly = FALSE
?Should I change the inputs from https://github.com/dreamRs/toastui/blob/master/inst/htmlwidgets/calendar.js under
cal.createSchedules([{}])
&Shiny.setInputValue({})
Please forgive my n000biness in Js.
Best,
Teo
The text was updated successfully, but these errors were encountered: