Skip to content

Instantly share code, notes, and snippets.

View bborgesr's full-sized avatar

Barbara Borges Ribeiro bborgesr

View GitHub Profile
@bborgesr
bborgesr / modular-processing.R
Created March 8, 2017 16:21
Processing input data, step by step, using Shiny modules
# -------------------------------------------------------------------
# ------------------ PROCESSING DATA MODULARLY----------------------
# -------------------------------------------------------------------
# This app processes some input text through three modules, passing
# the result of each module down to the next module. We're also
# displaying to the user the (reactive) result of each module, but
# usually we'd just be interested in the last one... In those cases,
# the modules' ui functions would be empty (except for the last
# module, of course).
@bborgesr
bborgesr / pseudo-navigation-shiny.R
Created June 30, 2017 20:43
Implements pseudo navigation in a Shiny app
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
tags$a("Go to Panel 1", href = "#panel1"), br(),
tags$a("Go to Panel 2", href = "#panel2"), br(),
tags$a("Go to Panel 3", href = "#panel3")
),
mainPanel(
@bborgesr
bborgesr / reset-fileInput-and-data.R
Created March 20, 2017 16:45
How to "reset" a fileInput widget and the underlying data (must treat these as two different things)
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
fileInput('inFile', 'Choose file'),
actionButton('reset', 'Reset'),
tableOutput('tbl')
)
@bborgesr
bborgesr / dynamic-dropdownMenu.R
Created May 9, 2017 16:58
How to dynamically add items to a dropdownMenu in shinydashboard
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Dropdowns 2.0",
dropdownMenuOutput("menu")
),
dashboardSidebar(
helpText("Add another item to the dropdown menu by clicking ",
"on the button below"),
@bborgesr
bborgesr / grokking_to_leetcode.md
Created May 14, 2022 05:12 — forked from tykurtz/grokking_to_leetcode.md
Grokking the coding interview equivalent leetcode problems

GROKKING NOTES

I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window

@bborgesr
bborgesr / shiny-reactive-R6-object.R
Created August 1, 2017 21:22
Uses the reactiveTrigger() construct in an R6 object class in order to make it useful in reactive settings, like a Shiny app (MWE included)
library(shiny)
reactiveTrigger <- function() {
counter <- reactiveVal( 0)
list(
depend = function() {
counter()
invisible()
},
trigger = function() {
@bborgesr
bborgesr / shiny-insertUI-removable.R
Last active June 7, 2023 12:07
Uses Shiny's insertUI to create elements (in this example, datatables) at the user's discretion; each of these comes with a button that will remove it from the app (using removeUI).
library(shiny)
ui <- fluidPage(
textInput("divID", "Enter an ID for the custom area:", ""),
helpText("Leave the text input blank for automatically unique IDs."),
actionButton("isrt", "Add a datatable"),
tags$div(id = "placeholder")
)
server <- function(input, output, session) {
rv <- reactiveValues()
@bborgesr
bborgesr / reactives-in-loops.R
Created March 5, 2017 19:20
How to use reactives in loops. What works, what doesn't and why.
# -------------------------------------------------------------------
# ------------------ REACTIVES INSIDE FOR LOOPS ---------------------
# -------------------------------------------------------------------
# -------------------------------------------------------------------
# --- EXAMPLE 1: this works fine, because there are no reactives in -
# --- the for lopp --------------------------------------------------
# -------------------------------------------------------------------
library(shiny)