title: R highcharter: putting heatmaps into motion
body: <p>I'm trying to use the <code>highcharter</code> R package "Motion Plugin", to make a Motion Chart for a heatmap. I.e. I would like a heatmap to change over time, using a slider with a play/pause button (see links below).</p>
  
  <p>I'm able to create a simple heatmap, for a specific year, e.g.:</p>
  
  <pre><code>df &lt;- tibble(year = c(rep(2016, 6), rep(2017, 6)),
           xVar = rep(c("a", "a", "b", "b", "c", "c"), 2),
           yVar = rep(c("d", "e"), 6),
           heatVar = rnorm(12))
  
  df %&gt;%
    filter(year == 2016) %&gt;%
    hchart(type = "heatmap", hcaes(x = xVar, y = yVar, value = heatVar)) %&gt;%
    hc_legend(layout = "vertical", verticalAlign = "top", align = "right")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/U2KKk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U2KKk.jpg" alt="highcharter heatmap"></a></p>
  
  <p>However, I'm struggling with making this a Motion Chart (sliding across 2016, 2017 in this example), using the <code>hc_motion(enabled = TRUE, ...)</code> function.</p>
  
  <p>I have read and followed these links:</p>
  
  <p><a href="https://www.r-bloggers.com/adding-motion-to-choropleths/" rel="nofollow noreferrer">https://www.r-bloggers.com/adding-motion-to-choropleths/</a></p>
  
  <p><a href="http://jkunst.com/highcharter/plugins.html" rel="nofollow noreferrer">http://jkunst.com/highcharter/plugins.html</a></p>
  
  <p>But no matter how I define my series, I do not get the expected result. Anyone can point me how the <code>xVar</code>, <code>yVar</code> series should be defined and the <code>hc_motion</code> function be used to make it work?</p>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p>Following <a href="https://stackoverflow.com/a/36075174/4095235">this</a> answer I managed to this using <code>shiny</code>, but I'd still prefer to avoid this solution:</p>
  
  <pre><code>server &lt;- shinyServer(function(input, output) {
  
    output$heatmap &lt;- renderHighchart({
  
    df &lt;- tibble(year = c(rep(2016, 6), rep(2017, 6)),
               xVar = rep(c("a", "a", "b", "b", "c", "c"), 2),
               yVar = rep(c("d", "e"), 6),
               heatVar = rnorm(12))
  
    # filter data based on selected year
    df.select &lt;- dplyr::filter(df, year == input$year) 
  
    # chart
    hchart(df.select, type = "heatmap", hcaes(x = xVar, y = yVar, value = heatVar))
  
  
  
    })
  
  })
  
  ui &lt;- shinyUI(fluidPage(
  
    # Application title
    titlePanel("Highcharts Heatmap Motion Chart"),
  
    # Sidebar with a slider input for the selected year
    sidebarLayout(
      sidebarPanel(
        sliderInput("year",
                    "Year:",
                    min = 2016,
                    max = 2017,
                    step = 1,
                    value = 2016,
                    animate = TRUE,
                    sep = "")
      ),
  
      # Show a bubble plot for the selected year
      mainPanel(
        highchartOutput("heatmap")
      )
    )
  ))
  
  shinyApp(ui = ui, server = server)
  </code></pre>