Skip to content

Commit

Permalink
Merge pull request #14 from Xymist/allow_use_in_evcxr
Browse files Browse the repository at this point in the history
Extract the render-to-string portion of to_html() into its own public method
  • Loading branch information
igiagkiozis committed Jun 28, 2020
2 parents 93f07e5 + 9a1ed12 commit ad74b00
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plotly/src/plot.rs
Expand Up @@ -194,13 +194,19 @@ impl Plot {
/// In contrast to `Plot::show()` this will save the resulting html in a user specified location
/// instead of the system temp directory.
pub fn to_html<P: AsRef<Path>>(&self, filename: P) {
let rendered = self.render(false, "", 0, 0);
let rendered = self.to_inline_html();
let rendered = rendered.as_bytes();
let mut file = File::create(filename.as_ref()).unwrap();
file.write_all(rendered)
.expect("failed to write html output");
}

/// Renders the contents of the `Plot` and returns it as a String, for embedding in
/// webpages or Jupyter notebooks.
pub fn to_inline_html(&self) -> String {
self.render(false, "", 0, 0)
}

/// Saves the `Plot` to png format.
#[cfg(feature = "orca")]
pub fn to_png<P: AsRef<Path>>(&self, filename: P, width: usize, height: usize) {
Expand Down Expand Up @@ -337,7 +343,10 @@ impl Plot {

#[cfg(target_os = "macos")]
fn show_with_default_app(temp_path: &str) {
Command::new("open").args(&[temp_path]).output().expect(DEFAULT_HTML_APP_NOT_FOUND);
Command::new("open")
.args(&[temp_path])
.output()
.expect(DEFAULT_HTML_APP_NOT_FOUND);
}

#[cfg(target_os = "windows")]
Expand Down

0 comments on commit ad74b00

Please sign in to comment.