Skip to content

Instantly share code, notes, and snippets.

@jjallaire
jjallaire / .gitignore
Last active November 2, 2023 14:19 — forked from wch/retirement-logo.png
Retirement simulation Quarto Shiny app
env/
__pycache__/
*-app.py
*_files/
*.html
@jjallaire
jjallaire / reveal.Rmd
Created March 24, 2016 14:14
reveal.js with custom css
---
title: "Untitled"
output:
revealjs::revealjs_presentation:
css: styles.css
---
## R Markdown
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF,
@jjallaire
jjallaire / server.R
Created December 18, 2013 12:55
Shiny Example 01_hello
library(shiny)
# Define server logic required to generate and plot a random distribution
shinyServer(function(input, output) {
# Expression that generates a plot of the distribution. The expression
# is wrapped in a call to renderPlot to indicate that:
#
# 1) It is "reactive" and therefore should be automatically
# re-executed when inputs change
'''Train MNIST with tfrecords yielded from a TF Dataset
In order to run this example you should first run 'mnist_to_tfrecord.py'
which will download MNIST data and serialize it into 3 tfrecords files
(train.tfrecords, validation.tfrecords, and test.tfrecords).
This example demonstrates the use of TF Datasets wrapped by a generator
function. The example currently only works with a fork of keras that accepts
`workers=0` as an argument to fit_generator, etc. Passing `workers=0` results
in the generator function being run on the main thread (without this various
@jjallaire
jjallaire / server.R
Created December 18, 2013 13:07
Shiny Example 06_tabsets
library(shiny)
# Define server logic for random distribution application
shinyServer(function(input, output) {
# Reactive expression to generate the requested distribution. This is
# called whenever the inputs change. The output functions defined
# below then all use the value computed from this expression
data <- reactive({
dist <- switch(input$dist,
@jjallaire
jjallaire / binner.cpp
Last active September 13, 2019 13:46 — forked from hadley/binner.cpp
#include <Rcpp.h>
using namespace Rcpp;
class BinFixed {
double width_;
double origin_;
public:
@jjallaire
jjallaire / multiplicative_lstm.R
Created October 26, 2018 13:15
Custom Multiplicative LSTM Layer for R Keras
library(keras)
library(reticulate)
layer_multiplicative_lstm <-function(
object, units, activation = "tanh", recurrent_activation = "hard_sigmoid", use_bias = TRUE,
return_sequences = FALSE, return_state = FALSE, go_backwards = FALSE, stateful = FALSE, unroll = FALSE,
kernel_initializer = "glorot_uniform", recurrent_initializer = "orthogonal", bias_initializer = "zeros",
unit_forget_bias = TRUE, kernel_regularizer = NULL, recurrent_regularizer = NULL, bias_regularizer = NULL,
from keras.models import Model
from keras import layers
from keras import Input
text_vocabulary_size = 10000
question_vocabulary_size = 10000
answer_vocabulary_size = 500
text_input = Input(shape=(None,), dtype='int32', name='text')
embedded_text = layers.Embedding(
@jjallaire
jjallaire / gist:bfc84ce7dd566a0a7231
Created February 17, 2015 22:15
custom finalizer
#include <Rcpp.h>
using namespace Rcpp;
void finalizeInt(int* ptr) {
// do nothing
}
typedef XPtr<int,PreserveStorage,finalizeInt> XPtrInt;
// [[Rcpp::export]]
@jjallaire
jjallaire / reveal-dygraph.Rmd
Created January 20, 2016 13:07
dygraphs with reveal.js
---
title: "Untitled"
output: revealjs::revealjs_presentation
---
## R Markdown
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.