Skip to content

Instantly share code, notes, and snippets.

@MayaGans
MayaGans / app.R
Created August 2, 2023 20:26
reactiveValues are weird and dont copy on modify
library(shiny)
ui <- fluidPage(
actionButton("debug", "DEBUG")
)
server <- function(input, output, session) {
inputs <- reactiveValues(a = 1)
new_inputs <- inputs
@MayaGans
MayaGans / split_tables
Created December 15, 2022 16:29
split tables with fixed columns
split_tables <- function(data, cols_to_freeze, max_col = 7) {
stopifnot(
"columns to fix do not exist in data" =
all(cols_to_freeze %in% names(data))
)
# we don't need to table wrap if the data is less than max_col
if (ncol(data) <= max_col) {
return(data)
library(dplyr)
library(rlang)
library(purrr)
library(learnr)
# TODO step 1 - turn the input DF into this list
# Input
quiz_list <- list(
@MayaGans
MayaGans / app.R
Created November 21, 2022 00:08
print tables to report
library(shiny)
ui <- fluidPage(
uiOutput("all_the_tables"),
downloadButton("download", "DOWNLOAD_ALL")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
```{ojs}
maya_utils = require('maya_utils')
```
```{ojs}
myNums = [1,2,3,1,4,1,2,5,3,4]
```
```{ojs}
uniqueNums = maya_utils.removeArrayDuplicates(myNums)
@MayaGans
MayaGans / app.R
Last active January 18, 2022 19:31
input hierarchy
library(shiny)
file_structure <- list(
LEVEL_1 = list(
LEVEL_2a = list(
LEVEL_3a1 = list(
LEVEL_4a1 = list()
),
LEVEL_3a2 = list(
LEVEL_4a3 = list()
@MayaGans
MayaGans / app.R
Created October 7, 2021 14:04
toggle color, multiple tables
library(shiny)
# note that the cells we want to toggle have a class called changes-color
df1 <- data.frame(
a = c(
"<div class='changes-color'>A</div>",
"<div>B</div>",
"<div class='changes-color'>C</div>"
)
)
@MayaGans
MayaGans / app.R
Created October 1, 2021 13:06
toggle class color
library(shiny)
# note that the cells we want to toggle have a class called changes-color
df <- data.frame(
a = c(
"<div class='changes-color'>A</div>",
"<div>B</div>",
"<div class='changes-color'>C</div>"
)
)
library(shiny)
library(DT)
data <- data.frame(
a = 1:3,
b = 2:4,
c = 5:7
)
table <- DT::datatable(
@MayaGans
MayaGans / d3.js
Last active September 20, 2021 15:30
// https://d3js.org v7.0.3 Copyright 2010-2021 Mike Bostock
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{})}(this,(function(t){"use strict";function n(t,n){return null==t||null==n?NaN:t<n?-1:t>n?1:t>=n?0:NaN}function e(t){let e=t,r=t,i=t;function o(t,n,e=0,o=t.length){if(e<o){if(0!==r(n,n))return o;do{const r=e+o>>>1;i(t[r],n)<0?e=r+1:o=r}while(e<o)}return e}return 1===t.length&&(e=(n,e)=>t(n)-e,r=n,i=(e,r)=>n(t(e),r)),{left:o,center:function(t,n,r=0,i=t.length){const a=o(t,n,r,i-1);return a>r&&e(t[a-1],n)>-e(t[a],n)?a-1:a},right:function(t,n,e=0,o=t.length){if(e<o){if(0!==r(n,n))return o;do{const r=e+o>>>1;i(t[r],n)<=0?e=r+1:o=r}while(e<o)}return e}}}function r(t){return null===t?NaN:+t}const i=e(n),o=i.right,a=i.left,u=e(r).center;var c=o;function f(t,n){let e=0;if(void 0===n)for(let n of t)null!=n&&(n=+n)>=n&&++e;else{let r=-1;for(let i of t)null!=(