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 / 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 / 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 / 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 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 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 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
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 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 / global.R
Created January 12, 2014 16:10
Demo on 'source' tags$style from global.R, alternative to includeCSS("www/style.css")
# global.R
# customize display settings here
gTags <- function() {
tags$head(
tags$style(
type = 'text/css'
, "body {font-size: 80%; color: rgb(0,0,100);}"
, "#mainPanelId {min-width: 50%; max-width: 70%; float: right;}"
, "#sidebarPanelId {min-width: 10%; max-width: 20%; float: left;}"
@ptoche
ptoche / server.R
Last active January 3, 2016 00:49
Demo on matrixInput from package shinyIncubator
# server.R
library("shiny")
library("shinyIncubator")
shinyServer(
function(input, output) {
# table of outputs
output$table <- renderTable({
res <- matrix(apply(input$data,1,prod))