JavaScript

Moving DOM Elements in Shiny

As a Shiny web developer it’s really common to leverage existing packages to create your HTML. But what if a package gets you 90% of where you want to go, and you want to customize it a little? In this tutorial I give a default DT table a small makeover by combining the datatable’s dataTables_length element and the datatables `dataTables_info element. How did I find the names of these elements?

R Functions I Took for Granted

I’m always trying to sharpen my JavaScript skills and I thought a good way of doing this would be to turn some dataframes I had lying around into JavaScript arrays of objects. What resulted is a love letter to the little R functions that are in actuality powerhouses and make our lives so easy because the best way I’ve seen to write these in JavaScript is, well, cray.

Recursion Again.... and Again.... and Again

I’ve gotten pretty far in the past year and a half or so of my limited JavaScript knowledge, but I still have some glaring gaps that I’d like to address. My familiarity with recursive functions ends after the classic Fibonacci sequence or counter example. I found myself asking okay but when am I actually going to use this? There must be a time were recursion will shine and I can’t just brute force my way through with a for loop….

GSAP & Xaringan

Greensock is a JavaScript library that lets you animate DOM elements. I’ve honestly learned everything I know about GSAP from their 20 minute tutorial video and trial and error. Here I’ll go over the three steps needed to animate an element of your Xaringan slides: Import the Greensock CDN into the head of your slide html Create the elements you want to animate in markdown Create a JavaScript file with the GSAP code to make those elements move.

JavaScript Statements

Computers are awesome for their ability to execute instructions. I mean, do you want to perform repetitive, error prone, menial tasks? Personally, I don’t want to spend time processing data, I just want to analyze it and eventually make pretty graphs. To do this though, the computer needs instructions, and these instructions come in the form of a list of statements. In this post I want to go over the grammar of JavaScript statements.

WTF is a Prototype

From Functions to Object Constructors Let’s start with a function called Person. This function is a class, also called an object constructor because it provides a blueprint to create new objects. It is the conveyor belt on which are objects are made. function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } Every object of class Person will accept two arguments, a string for first name and string for last name.

Why Would I setTimeout(0)?

Along with the hands-on skills I’ve been learning during my internship with RStudio, I’ve also been bolstering my theoretical understandings of programming concepts. This brought me to a common trick setTimeout(0), which defers the execution of a function, giving something else a chance to run. This concept was described using a concrete example in a StackOverflow post that I wanted to explore in more detail (both visually and without using JQuery):

Baby’s First Module

Modules are self contained scripts with their own distinct functionality. This allows for the addition or removal of modules as neccessary. It is easy enough to require modules using Node.js, but in the browser they behave very weirdly based on what browser you’re using. One of the quirks of JavaScripts! A book is organized into chapters, a good program is divided into modules. In my blockly big picture post I used an inelegant hack within the CreateDataSet block to include the stringified class code into the block itself.