This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You are an AI tutor and your job is to help the user learn the mapgl package in R. First introduce yourself to the user. | |
Your goal is to help the user learn to create interactive spatial visualizations using the mapgl package. Start by asking: What do you already know about spatial mapping in R? | |
Given this information, help students understand how to use mapgl to build interactive maps step by step, with special focus on going from “nothing to a cool map.” Tailor explanations, examples, and analogies to the user’s prior experience—especially if they are familiar with tidyverse and ggplot2. | |
Key elements of the topic are: | |
- How the mapgl model differs from ggplot2: maps are built with sources and layers (like Mapbox GL JS), not geoms or aesthetics. | |
- Initializing a map using maplibre() or mapboxgl(), and using bounds or fit_bounds() to center the map. | |
- Adding spatial data (usually sf objects) as layers with functions like add_fill_layer(), add_circle_layer(), or add_line_layer(). | |
- Using expressions like inte |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a sample R Shiny app chatbot that runs local models with an Ollama server. | |
# You also need Ollama installed and a ollama server running, plus at least one local model pulled. | |
# I hard-coded a few local models, | |
# If you use this, you'll want to hard code yours (including descriptions, or take those out) | |
# Coded with lots of LLM help + Posit's Shiny Assistant. | |
library(shiny) | |
library(shinychat) | |
library(bslib) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options(shiny.maxRequestSize = 5 * 1024^2) # Limit uploads to 5 MB | |
library(shiny) | |
library(magick) | |
library(base64enc) | |
library(bslib) | |
# Helper function to sanitize file names | |
safeFileName <- function(filename) { | |
gsub("[^a-zA-Z0-9_.-]", "_", filename) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Uses httr and jsonlite packages and optional DT to display results | |
library(httr) | |
library(jsonlite) | |
search_loc_images <- function(query, max_results = 10) { | |
# Base URL | |
base_url <- "https://www.loc.gov/photos/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code is a slight modification from the code at | |
# https://docs.chainlit.io/examples/qa | |
# that adds handling PDF and Word doc files in addition to text files | |
# Load all necessary libraries and modules | |
import chainlit as cl | |
from langchain.memory import ChatMessageHistory, ConversationBufferMemory | |
from langchain.docstore.document import Document | |
from langchain.prompts.chat import ( | |
ChatPromptTemplate, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: rocker/tidyverse:latest | |
pipelines: | |
default: | |
- step: | |
script: | |
- cd /opt/atlassian/pipelines/agent/build | |
- Rscript -e 'devtools::install_deps(".", dependencies=TRUE, upgrade=FALSE)' | |
- Rscript -e 'devtools::build()' | |
- Rscript -e 'devtools::install(upgrade_dependencies = FALSE)' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get all people you follow on Mastodon and which lists you've assigned them to. Inspired by Jon Udell doing this with Steampipe, his blog post: https://blog.jonudell.net/2022/12/22/lists-and-people-on-mastodon/ | |
library(rtoot) # need the dev version, and you need to have gotten and stored a user token | |
library(dplyr) | |
library(purrr) | |
library(magrittr) | |
library(glue) | |
# If you don't know your Mastodon account ID | |
my_display_name <- "YOUR DISPLAY NAME HERE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Winter | Total | |
---|---|---|
2000-01 | 45.9 | |
2001-02 | 15.1 | |
2002-03 | 70.9 | |
2003-04 | 39.4 | |
2004-05 | 86.6 | |
2005-06 | 39.9 | |
2006-07 | 17.1 | |
2007-08 | 51.2 | |
2008-09 | 65.9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_forecast_data <- function(city, forecast_url) { | |
req<-httr::GET(forecast_url) | |
json <- httr::content(req, as = "text") | |
weather_data <- jsonlite::fromJSON(json) | |
forecast_df <- weather_data$properties$periods | |
forecast_df <- forecast_df %>% | |
dplyr::mutate( | |
City = city, | |
Temp = if_else(isDaytime == TRUE, "High", "Low"), | |
Date = as.Date(substr(startTime,1,10)), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to set all vector items to blank except for every nth item | |
everyn <- function(myvec, n){ | |
myvec <- sort(unique(myvec)) | |
for(i in 1:length(myvec)) { | |
if( i %% n != 1) { | |
myvec[i] <- "" | |
} | |
} | |
return(myvec) |
NewerOlder