Skip to content

Instantly share code, notes, and snippets.

View ptoche's full-sized avatar
💭
fooling around

Patrick Toche ptoche

💭
fooling around
  • strange indentations
  • I live in Hong Kong in the U.S. time zone, but my heart is still in Europe.
View GitHub Profile
@ptoche
ptoche / server.R
Created January 13, 2014 18:14
Demo on debug panel, may be useful for large projects, something like this should be made into a convenience function and a basic part of shiny
# server.R
library("shiny")
shinyServer(
function(input, output, session) {
# Debug Area
output$Console <- renderUI({
@ptoche
ptoche / server.R
Last active January 3, 2016 07:39
Demo on actionButtons, reactiveValues and Sys.sleep()
# server.R
shinyServer(
function(input, output, session){
# Part I: create an observer on the state of actionButton "calculate"
busy <- reactiveValues(state = 0)
observe({
@ptoche
ptoche / server.R
Created January 16, 2014 19:10
Demo on why observe() and isolate() can be preferable to reactive()
# server.R
shinyServer(
function(input, output, session){
# This approach triggers a delay when the box is filled before the actionButton is actioned
# busyReactive <- reactive({
# delay <- as.integer(input$delay)
# if(input$trigger > 0) {Sys.sleep(delay)}
# return(input$trigger)
@ptoche
ptoche / server.R
Created January 16, 2014 19:31
Demo on a simple counter
# server.R
library("shiny")
library("shinyAce")
shinyServer(
function(input, output) {
# A reactiveValues object holds the value of the counter
values <- reactiveValues(i = 0)
@ptoche
ptoche / server.R
Created January 28, 2014 18:08
Demo on dynamic number of sliders
# server.R
shinyServer(function(input, output, session) {
output$sliders <- renderUI({
if (is.null(input$n) || is.na(input$n)) {
n <- 1
} else {
n <- round(input$n,0)
}
lapply(1:n, function(i) {
@ptoche
ptoche / server.R
Created January 28, 2014 22:03
Demo in Progress (very buggy) on sliderInput with numericInput for min/max
# server.R
library("shiny")
shinyServer(
function(input, output, session) {
# Reactive slider
v <- reactiveValues(min = -5, max = +5, status = 0)
@ptoche
ptoche / server.R
Created January 29, 2014 17:58
Demo on submit button with pop-up (IN PROGRESS)
# server.R
library("shiny")
shinyServer(
function(session, input, output) {
observe({
if (is.null(input$submit) || input$submit == 0){return()}
js_string <- 'alert("Do you want to submit now?");'
@ptoche
ptoche / make-and-crop.tex
Last active August 29, 2015 13:56
compile a latex image with pdflatex, convert to png, crop it, and clean up the temp files.
% !TeX document-id = {cf6594ac-97a2-46b5-af4f-f9d9c8aaa47d}
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass{article}%
\usepackage{filecontents}%
\begin{filecontents*}{tmp.tex}%
\input{tikz-board}%
\end{filecontents*}
%%
%% compile pdf
\immediate\write18{pdflatex tmp}
@ptoche
ptoche / chatJava.js
Last active August 29, 2015 13:56
Adapted Jeff Allen's "Chat Room"
// This script just listens for "enter"s on the text input and simulates
// clicking the "send" button when that occurs. Totally optional.
jQuery(document).ready(function(){
jQuery('#entry').keypress(function(evt){
if (evt.keyCode == 13){
// Enter, simulate clicking send
jQuery('#send').click();
}
});
})
@ptoche
ptoche / global.R
Last active August 29, 2015 13:56
demo of a shiny survey
# global.R
# Static Non-Reactive Area
# Read Survey Questions & Suggested Answers
Q <- read.csv("survey.csv", 'header' = FALSE)
# column 1 : questions
# column 2+: several answers
# Store Survey Questions & User Answers in a dataframe