Add crosstalk linking between listings map and table
All checks were successful
Deploy stAndrews / deploy (push) Successful in 4s

This commit is contained in:
2026-03-09 16:37:14 -04:00
parent 3a0ecf72f2
commit f466db6a9c

35
app.R
View File

@@ -6,10 +6,17 @@ library(sf)
library(dplyr)
library(leafpop)
library(DT)
library(crosstalk)
# load data ----
owners <- readRDS("./data/owners.rds")
listings <- readRDS("./data/listings.rds")
listings <- readRDS("./data/listings.rds") |>
arrange(price_per_sqft) |>
mutate(
price_fmt = scales::dollar(price),
ppsf_fmt = scales::dollar(price_per_sqft)
)
shared_listings <- SharedData$new(listings, key = ~address)
last_sale_date <- format(attr(owners, "last_sale_date"), "%Y-%m-%d")
sbdvn <- sf::st_read("./data/plats/plats.shp")
venice_bndry <- readRDS("./data/venice.rds")
@@ -480,7 +487,7 @@ server <- function(input, output) {
# listings map ----
output$listings_map <- renderLeaflet({
leaflet() |>
leaflet(shared_listings) |>
addProviderTiles("CartoDB.Voyager") |>
addPolygons(
data = sbdvn,
@@ -491,16 +498,14 @@ server <- function(input, output) {
label = ~sub_name
) |>
addMarkers(
data = listings,
lat = ~latitude,
lng = ~longitude,
popup = ~paste0(
"<b>", address, "</b><br>",
"Price: ", scales::dollar(price), "<br>",
"Price: ", price_fmt, "<br>",
"Sq Ft: ", sqft, "<br>",
"$/Sq Ft: ", scales::dollar(price_per_sqft)
),
clusterOptions = markerClusterOptions()
"$/Sq Ft: ", ppsf_fmt
)
) |>
setView(lng = -82.362253, lat = 27.076199, zoom = 16)
})
@@ -508,19 +513,17 @@ server <- function(input, output) {
# listings table ----
output$listings_table <- renderDT({
datatable(
listings |>
select(listed_date, address, sqft, price, price_per_sqft) |>
arrange(price_per_sqft) |>
mutate(
price = scales::dollar(price),
price_per_sqft = scales::dollar(price_per_sqft)
),
colnames = c("Listed", "Address", "Sq Ft", "Price", "$/Sq Ft"),
shared_listings,
colnames = c("Listed", "Address", "Sq Ft", "Price (raw)", "$/Sq Ft (raw)",
"Lat", "Lng", "Price", "$/Sq Ft"),
rownames = FALSE,
options = list(
pageLength = 25,
searching = FALSE,
dom = 't'
dom = 't',
columnDefs = list(
list(visible = FALSE, targets = c(3, 4, 5, 6))
)
)
)
})