@@ -61,9 +61,9 @@ plotly <- function(username=NULL, key=NULL){
61
61
if (is.null(key ))
62
62
key <- getOption(" plotlyKey" , stop(" you need an API key for Plot.ly - See the signup function" ))
63
63
64
- # public attributes/methods that the user has access to
65
- pub <- list (username = username , key = key , filename = " from api" , fileopt = NULL ,
66
- version = " 0.3.1 " )
64
+ # public attributes/methods that the user has access to
65
+ pub <- list (username = username , key = key , filename = " from api" , fileopt = NULL ,
66
+ version = " 0.4.0 " )
67
67
priv <- list ()
68
68
69
69
pub $ makecall <- function (args , kwargs , origin ) {
@@ -114,6 +114,38 @@ plotly <- function(username=NULL, key=NULL){
114
114
do.call(pub $ iplot , pargs )
115
115
}
116
116
}
117
+ pub $ get_figure <- function (file_owner , file_id ) {
118
+ headers = c(" plotly-username" = pub $ username ,
119
+ " plotly-apikey" = pub $ key ,
120
+ " plotly-version" = pub $ version ,
121
+ " plotly-platform" = " R" )
122
+ response_handler = basicTextGatherer()
123
+ header_handler = basicTextGatherer()
124
+ curlPerform(url = paste(" https://plot.ly/apigetfile" , file_owner , file_id , sep = " /" ),
125
+ httpheader = headers ,
126
+ writefunction = response_handler $ update ,
127
+ headerfunction = header_handler $ update )
128
+ resp_header = as.list(parseHTTPHeader(header_handler $ value()))
129
+
130
+ # Parse status
131
+ if (resp_header $ status != " 200" ) {
132
+ print(resp_header $ statusMsg )
133
+ stop(resp_header $ status )
134
+ }
135
+
136
+ body_string = response_handler $ value()
137
+ resp = RJSONIO :: fromJSON(body_string )
138
+ if (! is.null(resp $ error ) && resp $ error != " " )
139
+ stop(resp $ err )
140
+ if (! is.null(resp $ warning ) && resp $ error != " " )
141
+ cat(resp $ warning )
142
+ if (! is.null(resp $ message ) && resp $ error != " " )
143
+ cat(resp $ message )
144
+
145
+ fig = resp $ payload $ figure
146
+
147
+ return (fig )
148
+ }
117
149
pub $ iplot <- function (... , kwargs = list (filename = NULL , fileopt = NULL )) {
118
150
# Embed plotly graphs as iframes for knitr documents
119
151
r <- pub $ plotly(... , kwargs = kwargs )
0 commit comments