Skip to content

Instantly share code, notes, and snippets.

View bborgesr's full-sized avatar

Barbara Borges Ribeiro bborgesr

View GitHub Profile
@bborgesr
bborgesr / checkbox-choiceNames-flags.R
Created April 4, 2017 19:51
Demo of new `checkboxGroupInput()` and `radioButtons()` functionality in Shiny 1.0.1
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-1.0.1-new-features.R
Created March 30, 2017 17:21
"Exciting" new features in Shiny 1.0.1
# ----------------------------------------------------------------- #
# ------------- "Exciting" new features in Shiny 1.0.1 ------------ #
# ----------------------------------------------------------------- #
library(shiny)
# 1. ----------------------------------------------- #
# ------------------ reactiveVal() ----------------- #
# -------------------------------------------------- #
ui <- fluidPage(
@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 / 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 / hide-datatable-shiny.R
Created March 7, 2017 08:38
How to make a DataTable actually become hidden in a Shiny app
# -------------------------------------------------------------------
# ------------------ 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 / iterative-comp-shiny.R
Created March 6, 2017 16:53
An example of doing prolonged, iterative computation in Shiny. Adapted from: https://gist.github.com/trestletech/8608815
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
numericInput("steps", "Time steps:", 10, min=1),
actionButton("run", label="Start")
),
mainPanel(
textOutput("status")
@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)
@bborgesr
bborgesr / database-benchmarking.Rmd
Created June 23, 2016 17:52
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.
---
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)