Skip to content

Instantly share code, notes, and snippets.

@ageller
ageller / simpleMainPanel.R
Created March 25, 2022 15:31
A simple mainPanel example for a Shiny app
mainPanel(
plotOutput(“plot”)
)
@ageller
ageller / simpleRenderPlot.R
Created March 25, 2022 15:30
a simple renderPlot example for a Shiny app
output$plot <-renderPlot(
generate_plot(input$column)
)
@ageller
ageller / simpleSidebarPanel.R
Last active March 23, 2023 21:57
A simple sidebarPanel for a Shiny app
sidebarPanel(
selectInput(
"column" : "Data format:", columns
)
)
@ageller
ageller / typicalShinySkeleton.R
Last active July 27, 2023 10:31
typical Shiny app skeleton
# import libraries
library(shiny)
# possibly read in some data to be used below
# define the UI
ui <- fluidPage(
# app title
headerPanel("My Title"),
@ageller
ageller / ChicagoPotholes_7a_snippet.py
Last active December 21, 2021 14:47
example converting to geopandas to plot points
gdf1 = gpd.GeoDataFrame(df, geometry = gpd.points_from_xy(df['LONGITUDE'], df['LATITUDE']))
gdf1.iloc[0:100].plot(ax = ax, color = 'blue', markersize = 1.)
@ageller
ageller / ChicagoPotholes_6.py
Created December 20, 2021 22:19
create a histogram with dates
import matplotlib.pyplot as plt
import numpy as np
f, ax = matplotlib.pyplot.subplots()
minDate = np.datetime64('2011-01-01')
maxDate = np.datetime64('2019-01-01')
bins = np.arange(minDate, maxDate, np.timedelta64(1, 'M'),  dtype = 'datetime64[M]')
ax.hist(df['CREATION DATE'], bins = bins, orientation = 'horizontal')
@ageller
ageller / ChicagoPotholes_5.py
Last active November 13, 2023 19:05
create a choropleth
cmap = matplotlib.colormaps['Reds']
norm = matplotlib.colors.Normalize(vmin = min(gdf['Total Potholes']), vmax = max(gdf['Total Potholes']))
co = cmap(norm(gdf['Total Potholes']))
ap = norm((gdf['Total Potholes'])).clip(0,1)
gdf.plot(ax = ax, color = co, alpha = ap)
@ageller
ageller / ChicagoPotholes_4.py
Last active December 20, 2021 22:20
plot the GeoTIFF image
import rasterio rasterio
import matplotlib
f,ax = matplotlib.pyplot.subplots()
rasterio.plot.show(chicago.read(), ax = ax, transform = chicago.transform)
@ageller
ageller / ChicagoPotholes_3c_snippet.py
Created December 20, 2021 22:17
set column to datetime
df['CREATION DATE'] = pd.to_datetime(df['CREATION DATE'])
@ageller
ageller / ChicagoPotholes_3b_snippet.py
Created December 20, 2021 22:16
example to test if POINT is within POLYGON
if point.within(poly):
# do something