Skip to content

Instantly share code, notes, and snippets.

Avatar

Barbara Borges Ribeiro bborgesr

View GitHub Profile
@bborgesr
bborgesr / database-benchmarking.Rmd
Created Jun 23, 2016
Comparing the time that a query takes to run using three different models of database connection: one connection per program/app; one connection per query; using a connection pool.
View database-benchmarking.Rmd
---
title: "Benchmarking database queries"
author: "Barbara Borges Ribeiro"
date: "June 23, 2016"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(DBI)
@bborgesr
bborgesr / reactives-in-loops.R
Created Mar 5, 2017
How to use reactives in loops. What works, what doesn't and why.
View reactives-in-loops.R
# -------------------------------------------------------------------
# ------------------ REACTIVES INSIDE FOR LOOPS ---------------------
# -------------------------------------------------------------------
# -------------------------------------------------------------------
# --- EXAMPLE 1: this works fine, because there are no reactives in -
# --- the for lopp --------------------------------------------------
# -------------------------------------------------------------------
library(shiny)
@bborgesr
bborgesr / iterative-comp-shiny.R
Created Mar 6, 2017
An example of doing prolonged, iterative computation in Shiny. Adapted from: https://gist.github.com/trestletech/8608815
View iterative-comp-shiny.R
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
numericInput("steps", "Time steps:", 10, min=1),
actionButton("run", label="Start")
),
mainPanel(
textOutput("status")
@bborgesr
bborgesr / hide-datatable-shiny.R
Created Mar 7, 2017
How to make a DataTable actually become hidden in a Shiny app
View hide-datatable-shiny.R
# -------------------------------------------------------------------
# ------------------ HIDIND A DATATABLE IN SHINY --------------------
# -------------------------------------------------------------------
# -------------------------------------------------------------------
# --- EXAMPLE 1: this sets the datatable's underlying dataframe to --
# --- NULL, inside a reactive (recalculated whenever a checkbox is --
# --- clicked). While this does result in the datatable disappearing
# --- from view, the height does not show ---------------------------
@bborgesr
bborgesr / modular-processing.R
Created Mar 8, 2017
Processing input data, step by step, using Shiny modules
View modular-processing.R
# -------------------------------------------------------------------
# ------------------ 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 / reset-fileInput-and-data.R
Created Mar 20, 2017
How to "reset" a fileInput widget and the underlying data (must treat these as two different things)
View reset-fileInput-and-data.R
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
fileInput('inFile', 'Choose file'),
actionButton('reset', 'Reset'),
tableOutput('tbl')
)
@bborgesr
bborgesr / shiny-1.0.1-new-features.R
Created Mar 30, 2017
"Exciting" new features in Shiny 1.0.1
View shiny-1.0.1-new-features.R
# ----------------------------------------------------------------- #
# ------------- "Exciting" new features in Shiny 1.0.1 ------------ #
# ----------------------------------------------------------------- #
library(shiny)
# 1. ----------------------------------------------- #
# ------------------ reactiveVal() ----------------- #
# -------------------------------------------------- #
ui <- fluidPage(
@bborgesr
bborgesr / checkbox-choiceNames-flags.R
Created Apr 4, 2017
Demo of new `checkboxGroupInput()` and `radioButtons()` functionality in Shiny 1.0.1
View checkbox-choiceNames-flags.R
library(shiny)
countries <- c("Australia", "United Kingdom", "United States")
flags <- c(
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/au.svg",
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/gb.svg",
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/us.svg"
)
@bborgesr
bborgesr / shiny-simple-iterative-printing.R
Created May 5, 2017
Two simple examples of iterative printing in Shiny
View shiny-simple-iterative-printing.R
# By default Shiny will always wait for any reactive dependencies to finish (re)calculcating
# before displaying the output that depends on them. Without async reactivity in Shiny (which
# is not currently available, but it's in the works), it's actually not really possible to
# make a reactive dependency be available before it finishes computing. But you can redefine
# your reactive so that its output is broken though.
#
# You can achieve this using reactive values, an observer and invalidateLater(). If this is
# new for you, I'd recommend, you read the documentation about invalidateLater().
#
# I'll show two simple examples here. For a more elaborate example, see this gist.
@bborgesr
bborgesr / dynamic-dropdownMenu.R
Created May 9, 2017
How to dynamically add items to a dropdownMenu in shinydashboard
View dynamic-dropdownMenu.R
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"),