Skip to content

Instantly share code, notes, and snippets.

View kennedymwavu's full-sized avatar
🍀

Mwavu kennedymwavu

🍀
View GitHub Profile
@DeepanshKhurana
DeepanshKhurana / reactable_edit.R
Last active June 6, 2024 06:23
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 June 22, 2023 06:46
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 November 14, 2024 07:55
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 November 17, 2024 11:21
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
@cutiko
cutiko / Readme.md
Created November 22, 2019 18:24
Git delete last commit

Removing the last commit

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

If you want to "uncommit" the commits, but keep the changes around for reworking, remove the "--hard": git reset HEAD^ which will evict the commits from the branch and from the index, but leave the working tree around.

If you want to save the commits on a new branch name, then run git branch newbranchname before doing the git reset.

ORIGINAL did fork but search didn't helped me