Created
December 7, 2017 09:02
-
-
Save yaojenkuo/ecb1b35a6f6df120c9738351d5a099f6 to your computer and use it in GitHub Desktop.
gapminder_replica/plotlyGraphWidget.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This script is necessary in the app folder | |
#but the user should not have to edit it | |
#Output Graph Function | |
graphOutput <- function(inputId, width="100%", height="550px") { | |
tagList( | |
singleton(tags$head( | |
tags$script(src="plotlyGraphWidget.js") | |
)), | |
tags$iframe(id=inputId, src="https://plot.ly/~playground/7.embed", | |
class="graphs", style="border:none;", seamless=TRUE, width=width, height=height) | |
) | |
} | |
renderGraph <- function(expr, env=parent.frame(), quoted=FALSE) { | |
## This gets called when inputs change -- | |
## Place data wrangling code in here | |
## and pass the result to the client | |
## to be graphed. | |
installExprFunction(expr, "func", env, quoted) | |
function(){ | |
data = func(); | |
## data is the state of the widgets: see server.R | |
## this function returns a list of named lists that descripe | |
## valid postMessage commands to be sent to the embedded iframe. | |
## see binding.renderValue for the receiving JS side of this function | |
## and https://github.com/plotly/Embed-API for more about the postMessage | |
## graph messages | |
return(data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment