EVOLUTION-MANAGER
Edit File: onRender.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Execute custom JavaScript code after rendering</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for onRender {htmlwidgets}"><tr><td>onRender {htmlwidgets}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Execute custom JavaScript code after rendering</h2> <h3>Description</h3> <p>Use this function to supplement the widget's built-in JavaScript rendering logic with additional custom JavaScript code, just for this specific widget object. </p> <h3>Usage</h3> <pre> onRender(x, jsCode, data = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>An HTML Widget object</p> </td></tr> <tr valign="top"><td><code>jsCode</code></td> <td> <p>Character vector containing JavaScript code (see Details)</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>An additional argument to pass to the <code>jsCode</code> function. This can be any R object that can be serialized to JSON. If you have multiple objects to pass to the function, use a named list.</p> </td></tr> </table> <h3>Details</h3> <p>The <code>jsCode</code> parameter must contain valid JavaScript code which when evaluated returns a function. </p> <p>The function will be invoked with three arguments: the first is the widget's main HTML element, and the second is the data to be rendered (the <code>x</code> parameter in <code>createWidget</code>). The third argument is the JavaScript equivalent of the R object passed into <code>onRender</code> as the <code>data</code> argument; this is an easy way to transfer e.g. data frames without having to manually do the JSON encoding. </p> <p>When the function is invoked, the <code>this</code> keyword will refer to the widget instance object. </p> <h3>Value</h3> <p>The modified widget object </p> <h3>See Also</h3> <p><code><a href="onStaticRenderComplete.html">onStaticRenderComplete</a></code>, for writing custom JavaScript that involves multiple widgets. </p> <h3>Examples</h3> <pre> ## Not run: library(leaflet) # This example uses browser geolocation. RStudio users: # this won't work in the Viewer pane; try popping it # out into your system web browser. leaflet() %>% addTiles() %>% onRender(" function(el, x) { // Navigate the map to the user's location this.locate({setView: true}); } ") # This example shows how you can make an R data frame available # to your JavaScript code. meh <- "&#x1F610;"; yikes <- "&#x1F628;"; df <- data.frame( lng = quakes$long, lat = quakes$lat, html = ifelse(quakes$mag < 5.5, meh, yikes), stringsAsFactors = FALSE ) leaflet() %>% addTiles() %>% fitBounds(min(df$lng), min(df$lat), max(df$lng), max(df$lat)) %>% onRender(" function(el, x, data) { for (var i = 0; i < data.lng.length; i++) { var icon = L.divIcon({className: '', html: data.html[i]}); L.marker([data.lat[i], data.lng[i]], {icon: icon}).addTo(this); } } ", data = df) ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>htmlwidgets</em> version 1.5.1 <a href="00Index.html">Index</a>]</div> </body></html>