#' @import shiny
#' @import dplyr
#' @import rdrop2
app_server <- function(input, output, session) {
data <- loadData() %>% unique() %>% reactiveVal()
init_data <- isolate(data())
onStop(function() {
if (isolate(input$vote_button > 0)) {
save_data <- isolate(data())
saveData(unique(save_data))
}
})
join_festivals_react <- reactive({
join_festivals %>% filter_all(any_vars(grepl(input$text_filter, ., ignore.case = TRUE)))
})
# List the first level callModules here
output$mymap <- renderLeaflet({
leaflet(data = join_festivals_react()) %>% addTiles() %>%
addCircleMarkers(~long, ~lat,
popup = ~as.character(paste(sep = "<br/>", name, place, web, start, end, style, info)),
color = "red",
layerId = ~name,
clusterOptions = markerClusterOptions(zoomToBoundsOnClick = TRUE,
maxClusterRadius = 50
)) %>%
addProviderTiles(providers$Stamen.Toner) %>%
addMeasure(
position = "topright",
primaryLengthUnit = "meters",
primaryAreaUnit = "sqmeters",
activeColor = "#3D535D",
completedColor = "#7D4479"
) %>%
htmlwidgets::onRender("
function(el, x) {
this.on('popupopen', function(e) {
Shiny.onInputChange('myEvent', 'open');
});
this.on('popupclose', function(e) {
Shiny.onInputChange('myEvent', 'close');
});
}")
})
observe({
click <- input$mymap_marker_click
if(is.null(click))
return()
text <- paste0("You've selected festival '", click$id, "'. Wanna vote?!")
output$click_text <- renderText({ text })
})
observeEvent(input$vote_button, {
click <- input$mymap_marker_click
if(is.null(click))
return()
newLine <- isolate(data.table::data.table(name = input$text1, festival = click$id))
isolate(data(data.table::rbindlist(list(data(), newLine))))
})
output$infoText <- renderText({
print(str(input$mymap_marker_click))
})
observe({
click <- input$mymap_click
if(is.null(click))
return()
text <- ""
output$click_text <- renderText({ text })
})
output$table1 <- renderTable({data()})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.