Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Last active September 27, 2017 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpsievert/6f6bf66af283e4aef4015471ac2afd3d to your computer and use it in GitHub Desktop.
Save cpsievert/6f6bf66af283e4aef4015471ac2afd3d to your computer and use it in GitHub Desktop.
{"x":{"data":[{"orientation":"v","width":[0.310344827586207,0.310344827586207,0.310344827586207,0.310344827586207,0.310344827586206,0.310344827586207,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586207,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206],"base":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"x":[0.931034482758621,1.24137931034483,1.55172413793103,1.86206896551724,2.17241379310345,2.48275862068966,2.79310344827586,3.10344827586207,3.41379310344828,3.72413793103448,4.03448275862069,4.3448275862069,4.6551724137931,4.96551724137931,5.27586206896552,5.58620689655172,5.89655172413793,6.20689655172414,6.51724137931035,6.82758620689655,7.13793103448276,7.44827586206897,7.75862068965517,8.06896551724138,8.37931034482759,8.68965517241379,9,9.31034482758621,9.62068965517241,9.93103448275862],"y":[1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1],"text":["count: 1<br />1:10: 0.9310345","count: 0<br />1:10: 1.2413793","count: 0<br />1:10: 1.5517241","count: 1<br />1:10: 1.8620690","count: 0<br />1:10: 2.1724138","count: 0<br />1:10: 2.4827586","count: 0<br />1:10: 2.7931034","count: 1<br />1:10: 3.1034483","count: 0<br />1:10: 3.4137931","count: 0<br />1:10: 3.7241379","count: 1<br />1:10: 4.0344828","count: 0<br />1:10: 4.3448276","count: 0<br />1:10: 4.6551724","count: 1<br />1:10: 4.9655172","count: 0<br />1:10: 5.2758621","count: 0<br />1:10: 5.5862069","count: 1<br />1:10: 5.8965517","count: 0<br />1:10: 6.2068966","count: 0<br />1:10: 6.5172414","count: 0<br />1:10: 6.8275862","count: 1<br />1:10: 7.1379310","count: 0<br />1:10: 7.4482759","count: 0<br />1:10: 7.7586207","count: 1<br />1:10: 8.0689655","count: 0<br />1:10: 8.3793103","count: 0<br />1:10: 8.6896552","count: 1<br />1:10: 9.0000000","count: 0<br />1:10: 9.3103448","count: 0<br />1:10: 9.6206897","count: 1<br />1:10: 9.9310345"],"type":"bar","marker":{"autocolorscale":false,"color":"rgba(89,89,89,1)","line":{"width":1.88976377952756,"color":"transparent"}},"showlegend":false,"xaxis":"x","yaxis":"y","hoverinfo":"text","frame":null}],"layout":{"margin":{"t":35.8688346462804,"r":7.30593607305936,"b":49.8231725458238,"l":48.9497716894977},"plot_bgcolor":"rgba(235,235,235,1)","paper_bgcolor":"rgba(255,255,255,1)","font":{"color":"rgba(0,0,0,1)","family":"","size":14.6118721461187},"xaxis":{"domain":[0,1],"type":"linear","autorange":false,"range":[0.310344827586207,10.551724137931],"tickmode":"array","ticktext":["2.5","5.0","7.5","10.0"],"tickvals":[2.5,5,7.5,10],"categoryorder":"array","categoryarray":["2.5","5.0","7.5","10.0"],"nticks":null,"ticks":"outside","tickcolor":"rgba(51,51,51,1)","ticklen":3.65296803652968,"tickwidth":0.66417600664176,"showticklabels":true,"tickfont":{"color":"rgba(77,77,77,1)","family":"","size":11.689497716895},"tickangle":-0,"showline":false,"linecolor":null,"linewidth":0,"showgrid":true,"gridcolor":"rgba(255,255,255,1)","gridwidth":0.66417600664176,"zeroline":false,"anchor":"y","title":"1:10","titlefont":{"color":"rgba(0,0,0,1)","family":"","size":14.6118721461187},"hoverformat":".2f"},"yaxis":{"domain":[0,1],"type":"linear","autorange":false,"range":[-0.05,1.05],"tickmode":"array","ticktext":["0.00","0.25","0.50","0.75","1.00"],"tickvals":[0,0.25,0.5,0.75,1],"categoryorder":"array","categoryarray":["0.00","0.25","0.50","0.75","1.00"],"nticks":null,"ticks":"outside","tickcolor":"rgba(51,51,51,1)","ticklen":3.65296803652968,"tickwidth":0.66417600664176,"showticklabels":true,"tickfont":{"color":"rgba(77,77,77,1)","family":"","size":11.689497716895},"tickangle":-0,"showline":false,"linecolor":null,"linewidth":0,"showgrid":true,"gridcolor":"rgba(255,255,255,1)","gridwidth":0.66417600664176,"zeroline":false,"anchor":"x","title":"count","titlefont":{"color":"rgba(0,0,0,1)","family":"","size":14.6118721461187},"hoverformat":".2f"},"shapes":[{"type":"rect","fillcolor":null,"line":{"color":null,"width":0,"linetype":[]},"yref":"paper","xref":"paper","x0":0,"x1":1,"y0":0,"y1":1}],"showlegend":false,"legend":{"bgcolor":"rgba(255,255,255,1)","bordercolor":"transparent","borderwidth":1.88976377952756,"font":{"color":"rgba(0,0,0,1)","family":"","size":11.689497716895}},"hovermode":"closest","barmode":"relative"},"config":{"doubleClick":"reset","modeBarButtonsToAdd":[{"name":"Collaborate","icon":{"width":1000,"ascent":500,"descent":-50,"path":"M487 375c7-10 9-23 5-36l-79-259c-3-12-11-23-22-31-11-8-22-12-35-12l-263 0c-15 0-29 5-43 15-13 10-23 23-28 37-5 13-5 25-1 37 0 0 0 3 1 7 1 5 1 8 1 11 0 2 0 4-1 6 0 3-1 5-1 6 1 2 2 4 3 6 1 2 2 4 4 6 2 3 4 5 5 7 5 7 9 16 13 26 4 10 7 19 9 26 0 2 0 5 0 9-1 4-1 6 0 8 0 2 2 5 4 8 3 3 5 5 5 7 4 6 8 15 12 26 4 11 7 19 7 26 1 1 0 4 0 9-1 4-1 7 0 8 1 2 3 5 6 8 4 4 6 6 6 7 4 5 8 13 13 24 4 11 7 20 7 28 1 1 0 4 0 7-1 3-1 6-1 7 0 2 1 4 3 6 1 1 3 4 5 6 2 3 3 5 5 6 1 2 3 5 4 9 2 3 3 7 5 10 1 3 2 6 4 10 2 4 4 7 6 9 2 3 4 5 7 7 3 2 7 3 11 3 3 0 8 0 13-1l0-1c7 2 12 2 14 2l218 0c14 0 25-5 32-16 8-10 10-23 6-37l-79-259c-7-22-13-37-20-43-7-7-19-10-37-10l-248 0c-5 0-9-2-11-5-2-3-2-7 0-12 4-13 18-20 41-20l264 0c5 0 10 2 16 5 5 3 8 6 10 11l85 282c2 5 2 10 2 17 7-3 13-7 17-13z m-304 0c-1-3-1-5 0-7 1-1 3-2 6-2l174 0c2 0 4 1 7 2 2 2 4 4 5 7l6 18c0 3 0 5-1 7-1 1-3 2-6 2l-173 0c-3 0-5-1-8-2-2-2-4-4-4-7z m-24-73c-1-3-1-5 0-7 2-2 3-2 6-2l174 0c2 0 5 0 7 2 3 2 4 4 5 7l6 18c1 2 0 5-1 6-1 2-3 3-5 3l-174 0c-3 0-5-1-7-3-3-1-4-4-5-6z"},"click":"function(gd) { \n // is this being viewed in RStudio?\n if (location.search == '?viewer_pane=1') {\n alert('To learn about plotly for collaboration, visit:\\n https://cpsievert.github.io/plotly_book/plot-ly-for-collaboration.html');\n } else {\n window.open('https://cpsievert.github.io/plotly_book/plot-ly-for-collaboration.html', '_blank');\n }\n }"}],"cloud":false},"source":"A","attrs":{"65785f79881c":{"x":{},"type":"bar"}},"cur_data":"65785f79881c","visdat":{"65785f79881c":["function (y) ","x"]},"highlight":{"on":"plotly_click","persistent":false,"dynamic":false,"selectize":false,"opacityDim":0.2,"selected":{"opacity":1}},"base_url":"https://plot.ly"},"evals":["config.modeBarButtonsToAdd.0.click"],"jsHooks":{"render":[{"code":"function(el, x) { var ctConfig = crosstalk.var('plotlyCrosstalkOpts').set({\"on\":\"plotly_click\",\"persistent\":false,\"dynamic\":false,\"selectize\":false,\"opacityDim\":0.2,\"selected\":{\"opacity\":1}}); }","data":null},{"code":"function(el, x) { var ctConfig = crosstalk.var('plotlyCrosstalkOpts').set({\"on\":\"plotly_click\",\"persistent\":false,\"dynamic\":false,\"selectize\":false,\"opacityDim\":0.2,\"selected\":{\"opacity\":1}}); }","data":null}]}}
library(plotly)
jsonify <- function(x, ...) {
b <- plotly_build(x)
plotly:::to_JSON(htmlwidgets:::createPayload(b), ...)
}
json <- jsonify(ggplotly(qplot(1:10)))
writeLines(json, "ggbasic.json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment