Skip to content

Instantly share code, notes, and snippets.

View kennedymwavu's full-sized avatar
🍀

Mwavu kennedymwavu

🍀
View GitHub Profile
@J-Moravec
J-Moravec / serve.r
Last active December 8, 2024 05:07
Implementation of a local server for static website using the R's internal httpd server.
error404 = paste0(
"<!DOCTYPE html>",
"<html lang=\"en\">",
"<head>",
" <meta charset=\"UTF-8\">",
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
" <title>Resources not found</title>",
"</head>",
"<body>",
" <div class=\"main\">",
@DeepanshKhurana
DeepanshKhurana / reactable_edit.R
Last active February 11, 2025 15:01
Editable Reactable (with Modals)
library(shiny)
library(reactable)
library(dplyr)
ui <- fluidPage(
actionButton(inputId = "edit",
label = "Edit"),
reactableOutput("table")
)
@rasmusab
rasmusab / chat-gtp-api-call.R
Last active May 8, 2025 08:17
How to call the ChatGTP API from R (in 2023-03-01)
# How to call the new (as of 2023-03-01) ChatGTP API from R
# Get your API key over here: https://platform.openai.com/
api_key <- "sk-5-your-actual-api-key-Fvau6" # Don't share this! 😅
library(httr)
library(stringr)
# Calls the ChatGTP API with the given promps and returns the answer
ask_chatgtp <- function(prompt) {
response <- POST(
@kennedymwavu
kennedymwavu / install.R
Created June 22, 2022 11:56
Selectively install packages. If it's already installed don't reinstall.
# Just copy paste your "library" statements here using {datapasta}:
packages <- c(
"library(shiny)", "library(bs4Dash)", "library(shinyjs)",
"library(shinyWidgets)", "library(firebase)", "library(glue)",
"library(DBI)", "library(RPostgres)", "library(lubridate)",
"library(htmlwidgets)", "library(shinybusy)"
)
# rm "library()" leaving bare pkg chars:
pkg_nms <- gsub(pattern = "library\\(", replacement = "", x = packages) |>
@nanxstats
nanxstats / shiny-file-input-area.R
Created April 18, 2022 01:50
Shiny file input area (Bootstrap 5)
fileInputArea <- function(inputId, label, multiple = FALSE, accept = NULL,
width = NULL, buttonLabel = "Browse...", placeholder = "No file selected") {
restoredValue <- restoreInput(id = inputId, default = NULL)
# Catch potential edge case - ensure that it's either NULL or a data frame.
if (!is.null(restoredValue) && !is.data.frame(restoredValue)) {
warning("Restored value for ", inputId, " has incorrect format.")
restoredValue <- NULL
}
@nanxstats
nanxstats / shiny-bs5-switches.R
Created April 14, 2022 04:26
Bootstrap 5 Switches for Shiny
switchInput <- function(inputId, label, value = FALSE, disabled = FALSE, width = NULL) {
value <- shiny::restoreInput(id = inputId, default = value)
inputTag <- htmltools::tags$input(id = inputId, type = "checkbox", role = "switch", class = "form-check-input")
if (!is.null(value) && value) {
inputTag$attribs$checked <- NA
}
if (!is.null(disabled) && disabled) {
inputTag$attribs$disabled <- NA
}
htmltools::tags$div(
@plembo
plembo / ghpwithnamecheap.md
Last active April 8, 2025 03:29
GitHub Pages with Namecheap custom domain

Using GitHub Pages with a custom domain: Namecheap Edition

As often happens, I found the official documentation and forum answers to be "close, but no cigar", and so had to experiment a little to get things working.

The main problem for me was a lack of concrete configuration examples. That's not entirely GitHub's fault: having migrated from Google Domains to Namecheap in the middle of this project, I was once again reminded of how many different ways there are to do things in the name service universe [1].

Although you'd think the simplest setup would be to merely configure for the subdomain case (https://www.example.com), in my experience using the apex domain (https://example.com) instead resulted in fewer complications.

Procedure

So here's my recipe for using a custom domain with GitHub pages where Namecheap is the DNS provider:

@jcheng5
jcheng5 / README.md
Last active November 13, 2024 05:46
Accepting POST requests from Shiny

Accepting POST requests from Shiny

(This post was motivated by a talk by @jnolis at CascadiaRConf 2021)

Recent versions of Shiny have an undocumented feature for handling POST requests that are not associated with any specific Shiny session. (Note that this functionality is missing our normal level of polish; it's a fairly low-level hook that I needed to make some things possible, but doesn't make anything easy.)

In a nutshell, it works by replacing your traditional ui object with a function(req), and then marking that function with an attribute indicating that it knows how to handle both GET and POST:

library(shiny)
@tanho63
tanho63 / position-picker-input.R
Last active November 9, 2022 08:26
pickerInput example
positions <- data.frame(pos = c("QB","RB","WR","TE"),
posdesc = c("Quarterback","Running Back","Wide Receiver","Tight End"))
shinyWidgets::pickerInput(
inputId = 'positions',
label = 'position',
choices = positions$pos,
selected = positions$pos,
multiple = TRUE,
options = list(
@rahularity
rahularity / work-with-multiple-github-accounts.md
Last active May 15, 2025 08:31
How To Work With Multiple Github Accounts on your PC

How To Work With Multiple Github Accounts on a single Machine

Let suppose I have two github accounts, https://github.com/rahul-office and https://github.com/rahul-personal. Now i want to setup my mac to easily talk to both the github accounts.

NOTE: This logic can be extended to more than two accounts also. :)

The setup can be done in 5 easy steps:

Steps:

  • Step 1 : Create SSH keys for all accounts
  • Step 2 : Add SSH keys to SSH Agent