Skip to content

Instantly share code, notes, and snippets.

@ksonda
ksonda / server.R
Created January 31, 2020 15:25 — forked from trestletech/server.R
A Shiny app combining the use of dplyr and SQLite. The goal is to demonstrate a full-fledged, database-backed user authorization framework in Shiny.
library(shiny)
library(dplyr)
library(lubridate)
# Load libraries and functions needed to create SQLite databases.
library(RSQLite)
library(RSQLite.extfuns)
saveSQLite <- function(data, name){
path <- dplyr:::db_location(filename=paste0(name, ".sqlite"))
@ksonda
ksonda / nldi_mapper.R
Created June 4, 2021 14:47
R NLDI Mapview function
library(mapview)
library(urltools)
library(nhdplusTools)
library(sf)
convert <- function(x) {
for(n in names(x)) {
if(is.character(x[[n]])) {
test <- grepl("^http", x[[n]])
@ksonda
ksonda / docker-compose.yml
Created January 19, 2022 15:30
docker-compose for frost with chillimport
version: '3.4'
services:
chill-import:
image: fraunhoferiosb/chillimport:latest
ports:
- "8000:8000"
environment:
- configPath="/data"
volumes:
@ksonda
ksonda / combine_csv.R
Last active February 18, 2022 01:34
combine csvs in R
library(readr)
library(dplyr)
csv_directory <- "."
output_directory <- "./results"
filenames <- list.files(csv_directory,pattern="*.csv")
all_files <- Reduce(bind_rows, lapply(filenames, read_csv, col_types = cols(.default = "c")))
@ksonda
ksonda / docker-compose.yml
Last active March 9, 2022 20:33
docker-compose for website with sensorthings and R
version: '3.4'
services:
caddy:
image: caddy:2.4.6-alpine
container_name: webserver
ports:
- 80:80
- 443:443
volumes:
- ./nc-water-supply:/srv
@ksonda
ksonda / Caddyfile
Last active March 9, 2022 20:31
Caddyfile water supply dashboard
r.boerne-water-dashboard.internetofwater.app {
reverse_proxy rstudio:8787
}
boerne-water-dashboard.internetofwater.app {
root * /srv
file_server
}
@ksonda
ksonda / hydroshare-update.R
Last active May 25, 2022 14:47
update-hydroshare-file
####################
# Using R to update a file in a Hydroshare resource
library(sf)
library(httr)
## make some data
d <- read_sf("https://reference.geoconnex.us/collections/states/items?limit=100")
## Write out the data
file <- "out.gpkg"
@ksonda
ksonda / wade-geoconnex.jsonld
Last active June 6, 2022 14:20
wade geoconnex template
{
"@context": [{
"schema": "http://schema.org/",
"skos": "https://www.w3.org/TR/skos-reference/",
"sosa": "http://www.w3.org/ns/sosa/",
"hyf": "https://www.opengis.net/def/schema/hy_features/hyf/",
"gsp": "http://www.opengeospatial.org/standards/geosparql/",
"name": "schema:name",
"sameAs": "schema:sameAs",
"related": "skos:related",
@ksonda
ksonda / r-geoconnex.R
Last active November 28, 2022 15:44
R sparql demo for geoconnex
##packages used
require(sf)
require(SPARQL)
# remotes::install_github("cran/SPARQL") this is archived by cran grrrr
require(mapview)
require(dplyr)
library(stringi)
# start gage
gage_uri <- "https://geoconnex.us/ref/gages/1118104"
@ksonda
ksonda / query.md
Last active December 5, 2022 02:55
usgs-sensorthings-by-mainstem-query

https://labs.waterdata.usgs.gov/sta/v1.1/Locations?$filter=properties/mainstemURL%20eq%20%27https://geoconnex.us/ref/mainstems/29559%27&$expand=Things($select=id)/Datastreams($filter=properties/ParameterCode%20eq%20%2700065%27)/Observations($top=1)&$resultFormat=GeoJSON"

https://labs.waterdata.usgs.gov/sta/v1.1/Locations?$filter=properties/mainstemURL%20eq%20%27https://geoconnex.us/ref/mainstems/29559%27&$expand=Things($select=id)/Datastreams($filter=properties/ParameterCode%20eq%20%2700065%27)/Observations($top=1)&$resultFormat=GeoJSON"