Skip to content

Instantly share code, notes, and snippets.

@geotheory
Last active February 6, 2022 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geotheory/0db55679de75cb784686296a777638a0 to your computer and use it in GitHub Desktop.
Save geotheory/0db55679de75cb784686296a777638a0 to your computer and use it in GitHub Desktop.
require(tmap)
require(dplyr)
require(stars)
require(shiny)
server = shinyServer(function(input, output, session) {
tmap_mode("view")
output$map = renderTmap({
set.seed(round(input$seed))
d = data.frame(lon = rnorm(1e5, mean = -95.5, sd=4) |> pmin(179) |> pmax(-179),
lat = rnorm(1e5, mean = 37.5, sd=4) |> pmin(89) |> pmax(-89)) |>
group_by(lat = round(lat), lon = round(lon)) |>
summarise(n = length(lat), .groups = 'drop') |>
st_as_sf(coords = c('lon','lat'), crs = 'WGS84') |>
st_rasterize()
set.seed(42) # to prove bug is data related
tm_basemap("Stamen.TonerLite") +
tm_shape(d) +
tm_raster("n", palette = c('white','red'), alpha=0.5)
})
})
ui = fluidPage(
absolutePanel(bottom = 100, left = 50, style = 'z-index: 100;',
numericInput('seed', 'Seed', value = 54)
),
tmapOutput('map', width = '98vw', height = '93vh')
)
shinyApp(ui, server, options = list(launch.browser = FALSE))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment