Add crosstalk linking between listings map and table
All checks were successful
Deploy stAndrews / deploy (push) Successful in 4s
All checks were successful
Deploy stAndrews / deploy (push) Successful in 4s
This commit is contained in:
35
app.R
35
app.R
@@ -6,10 +6,17 @@ library(sf)
|
|||||||
library(dplyr)
|
library(dplyr)
|
||||||
library(leafpop)
|
library(leafpop)
|
||||||
library(DT)
|
library(DT)
|
||||||
|
library(crosstalk)
|
||||||
|
|
||||||
# load data ----
|
# load data ----
|
||||||
owners <- readRDS("./data/owners.rds")
|
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")
|
last_sale_date <- format(attr(owners, "last_sale_date"), "%Y-%m-%d")
|
||||||
sbdvn <- sf::st_read("./data/plats/plats.shp")
|
sbdvn <- sf::st_read("./data/plats/plats.shp")
|
||||||
venice_bndry <- readRDS("./data/venice.rds")
|
venice_bndry <- readRDS("./data/venice.rds")
|
||||||
@@ -480,7 +487,7 @@ server <- function(input, output) {
|
|||||||
|
|
||||||
# listings map ----
|
# listings map ----
|
||||||
output$listings_map <- renderLeaflet({
|
output$listings_map <- renderLeaflet({
|
||||||
leaflet() |>
|
leaflet(shared_listings) |>
|
||||||
addProviderTiles("CartoDB.Voyager") |>
|
addProviderTiles("CartoDB.Voyager") |>
|
||||||
addPolygons(
|
addPolygons(
|
||||||
data = sbdvn,
|
data = sbdvn,
|
||||||
@@ -491,16 +498,14 @@ server <- function(input, output) {
|
|||||||
label = ~sub_name
|
label = ~sub_name
|
||||||
) |>
|
) |>
|
||||||
addMarkers(
|
addMarkers(
|
||||||
data = listings,
|
|
||||||
lat = ~latitude,
|
lat = ~latitude,
|
||||||
lng = ~longitude,
|
lng = ~longitude,
|
||||||
popup = ~paste0(
|
popup = ~paste0(
|
||||||
"<b>", address, "</b><br>",
|
"<b>", address, "</b><br>",
|
||||||
"Price: ", scales::dollar(price), "<br>",
|
"Price: ", price_fmt, "<br>",
|
||||||
"Sq Ft: ", sqft, "<br>",
|
"Sq Ft: ", sqft, "<br>",
|
||||||
"$/Sq Ft: ", scales::dollar(price_per_sqft)
|
"$/Sq Ft: ", ppsf_fmt
|
||||||
),
|
)
|
||||||
clusterOptions = markerClusterOptions()
|
|
||||||
) |>
|
) |>
|
||||||
setView(lng = -82.362253, lat = 27.076199, zoom = 16)
|
setView(lng = -82.362253, lat = 27.076199, zoom = 16)
|
||||||
})
|
})
|
||||||
@@ -508,19 +513,17 @@ server <- function(input, output) {
|
|||||||
# listings table ----
|
# listings table ----
|
||||||
output$listings_table <- renderDT({
|
output$listings_table <- renderDT({
|
||||||
datatable(
|
datatable(
|
||||||
listings |>
|
shared_listings,
|
||||||
select(listed_date, address, sqft, price, price_per_sqft) |>
|
colnames = c("Listed", "Address", "Sq Ft", "Price (raw)", "$/Sq Ft (raw)",
|
||||||
arrange(price_per_sqft) |>
|
"Lat", "Lng", "Price", "$/Sq Ft"),
|
||||||
mutate(
|
|
||||||
price = scales::dollar(price),
|
|
||||||
price_per_sqft = scales::dollar(price_per_sqft)
|
|
||||||
),
|
|
||||||
colnames = c("Listed", "Address", "Sq Ft", "Price", "$/Sq Ft"),
|
|
||||||
rownames = FALSE,
|
rownames = FALSE,
|
||||||
options = list(
|
options = list(
|
||||||
pageLength = 25,
|
pageLength = 25,
|
||||||
searching = FALSE,
|
searching = FALSE,
|
||||||
dom = 't'
|
dom = 't',
|
||||||
|
columnDefs = list(
|
||||||
|
list(visible = FALSE, targets = c(3, 4, 5, 6))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user