I'm trying to update a GT table with selected markers in a leaflet marker but for the life of me I cannot get it to update the table. There are no errors when I run the app, and there are no errors in the console when trying to select a marker.
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Sales Volume Map Report"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectizeInput("Primary_Provider","Choose Primary Provider",selected = NULL,choices = c("",unique(providers$ProviderNumber))),
selectizeInput("Compare_Group","Choose Providers to Compare",choices = c(unique(providers$ProviderNumber)),multiple = TRUE),
numericInput("radius", "Choose Radius in Miles:", 10, min = 1, max = 1000),
downloadButton("download")
),
# Show a plot of the generated distribution
mainPanel(
leafletOutput("mymap"),
gt_output(outputId = "table")
)
)
)
server <- function(input, output, session) {
my_gt_object <- reactive(gt(data %>%
dplyr::select(ProviderNumber,Facilityname,Year,Service_Line,Corazon_Category,volume) %>%
dplyr::mutate(Corazon_Category = case_when(str_detect(Corazon_Category,"PCI & PV") ~ "PCI", TRUE ~ Corazon_Category)) %>%
dplyr::filter(ProviderNumber == input$Primary_Provider | ProviderNumber %in% c(input$Compare_Group)) %>%
dplyr::group_by(ProviderNumber,Facilityname,Year,Service_Line,Corazon_Category) %>%
pivot_wider(names_from = Year,values_from = volume,names_sort = TRUE ,values_fn = \(volume) sum(volume, na.rm = TRUE)) %>%
dplyr::mutate(Case_Change = `2020` -`2019`) %>%
dplyr::mutate(Percent_change = (`2020` -`2019`) / `2020` ) %>%
dplyr::mutate(primary = case_when(ProviderNumber == input$Primary_Provider ~ 1,FALSE ~ 0)) %>%
dplyr::arrange(desc(primary),Service_Line,Corazon_Category) %>%
dplyr::select(-c(ProviderNumber)),
groupname_col = c("Service_Line","Corazon_Category")
)
output$table <- render_gt(my_gt_object())
output$mymap <- renderLeaflet({
leaflet(cords) %>%
addTiles() %>%
addCircles(data = (cords %>%
dplyr::filter(providernumber == input$Primary_Provider)),lng = ~longitude, lat = ~latitude, color = 'black', fillColor = 'Red',
radius = (input$radius*1609.344), opacity = .3) %>%
addCircleMarkers(lng = ~longitude, lat = ~latitude,
popup = ~as.character(providernumber), label = ~as.character(providernumber)) %>%
addCircleMarkers(data = (cords %>%
dplyr::filter(providernumber == input$Primary_Provider)),lng = ~longitude, lat = ~latitude,color = 'Green')
})
observeEvent(input$sitemap_marker_click, {
click <- input$sitemap_marker_click
updateSelectInput(session, "Compare_Group",
selected = c(click$id[!click$id %in% input$Compare_Group],
input$Compare_Group[input$Compare_Group != click$id]))
})