shinysense

Helping shiny sense the world around it

Nick Strayer

Outline

  • Who am I?
  • What…
    • is shinysense?
    • senses does it have?
  • How…
    • is it made?
    • do I use it?
  • Why?
    • Shiny’s Role in Data Science.
    • Papr.
  • Where…
    • is it being used?
    • do I see it going?

Who am I?

What?

What is shinysense

  • A package filled with shiny modules that use javascript to gather data from various sensors.
  • Mobile first (aka I haven’t figured out how to make some of the functions work well on desktop.)

What senses are present?

Touch

shinyswipr

  • Embeds a card that can be swiped in different directions, the swipe direction is returned to shiny.
  • Used in our app papr.
  • Demo. Code for demo.

Touch

shinydrawr

Hearing

shinyear

  • Records audio on a button press and returns the fast-fourier transformed signal to the server.
  • Demo. Code.

Motion

shinymovr

  • Capture and return accelerometer data from your phone or tablet.
  • Demo. Code.

Sight

shinysee

  • Record images from a a webcam or mobile camera (android only unfortunately).
  • Coming soon…

Helpers

shinypopup

  • A lot of times when you’re developing an app using the above senses you need to let your user’s know you’re collecting their data. This module creates a popup that obscures a given section of your app that forces the user to accept your terms before they can go any further.
  • Used in papr to force people to accept our data use agreement.
  • Demo. Code.

Why?

Shiny’s Role in Data Science

Shiny is a great tool for presenting models/ analysis. But what about gathering the data?

Where Shiny sits now.

Overly ambitious goal.

Mobile

A lot of shiny apps don’t work well on mobile as they have been (understandably) built around a mouse and keyboard.

shinysense tries to make it easier to build mobile friendly apps.

This allows the use of shiny apps in environments where the user can’t sit down at a computer.

Papr

We were building a rather complex app and it was getting out of control, so we modularized.

This saved us lines of code and allowed the UI to be more declarative.

How?

How is it made?

  • The R side
    • Shiny Modules
  • Javascript side
    • Custom javascript libraries.

Shiny Modules

A formalized way bundling chunks of code in shiny apps for reuse. Aka functions but with some nice added features.

sayMessageUI <- function(id) {
  ns <- NS(id) #namespace function for keeping message unique
  p( textOutput(ns("sayMessage")) )
}
sayMessage <- function(input, output, session, message = "hi") {
  output$sayMessage <- renderText({ message })
}
ui <- fluidPage(
   titlePanel("useR Brussles Example"),
   sayMessageUI("message1"),
   sayMessageUI("message2")
)
server <- function(input, output) {
  message_1 <- callModule(sayMessage, "message1", "I'm just here for the")
  message_2 <- callModule(sayMessage, "message2", "beer and chocolate.")
}

Javascript Binding

  • Javascript has a ton of APIs for gathering data for input.
  • shinysense taps into these and makes them available to R.
class shinymovr{
  constructor(params){
    this.isOn = false;       //are we currently recording data?
    this.movement_data = []; //holds the most recent recordings data.
    this.send_dest = params.destination + "movement";
    this.watcher = this.make_watcher(params);
    document.getElementById(params.id).addEventListener("click", this.toggleButton.bind(this), true);
  }
  make_watcher(params){
    params.dom_target     = params.id;
    params.onMoveFunction = this.gather.bind(this);    //function that accumulates data while recording.
    return acceljs.accel(params);
  }
  ...};
  //watch for message from server saying it's ready.
  Shiny.addCustomMessageHandler("initialize_movr",
      params =>  new shinymovr(params)
  );
  ...

link to code

How do I use it?

Installation

  • Not on Cran so you have to install it from github.
  • devtools::install_github("nstrayer/shinysense")

Using in your app

  • Uses the standard module formulation.
  • UI: shinydrawrUI("outbreak_stats")
  • Server: callModule(shinydrawr, "outbreak_stats", my_data, draw_start = 15)

Demo

Where

Is it being used?

A few people have already bravely started using shinysense.

  • Papr
    • Description: Tinder-esque way of taking the last pure thing in our society and corrupting it.
    • Uses: shinyswipr, shinypopup.
  • Louisville Crime Rates
    • Description: Guess temporal trends in crime rates in the city of Louisville.
    • Uses: shinydrawr.
  • GenomeBot Tweet Generator
    • Description: Rate the output of a model by swiping directly on it.
    • Uses: shinyswipr.
  • contributr
    • Description: rOpenSci project to help connect useRs with github issues.
    • Uses: shinyswipr.

Where is shinysense now?

Currently it could be classified as whatever comes before alpha in the development cycle.

There are lots of bugs and testing for the R code is not implemented at all. (Still building a swiping robot).

Still it has been used in some well trafficked apps and doesn’t seem to have caused any serious harm.

Where do I see it going?

Becoming an easy to use, thoughtless process for gathering data.

Easing the process of deploying statistical models in real-world environments such as emergency rooms, etc.

CRAN… eventually.

Thanks!

Some potentially valuable info: