Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iframes only work when pressing knit html button in rstudio #12

Closed
sckott opened this issue Apr 18, 2014 · 14 comments
Closed

iframes only work when pressing knit html button in rstudio #12

sckott opened this issue Apr 18, 2014 · 14 comments
Labels

Comments

@sckott
Copy link
Contributor

sckott commented Apr 18, 2014

Or at least for some people the hook only works when pressing knit html button in rstudio.

Perhaps we need to edit the knit hook to make it work in any context.

@sckott sckott added the bug label Apr 18, 2014
@tdhock
Copy link
Contributor

tdhock commented Apr 19, 2014

Hm, I am not an expert in writing knit hooks, so do you have any ideas? In
practice I just use the knit html button in rstudio. The other context is
just using knit2html on the R command line?

Another thing that would be nice but I don't have any idea how to do is to
change the knit hook to automatically detect and embed plotlys (rather than
having to specify plotly=TRUE), any idea how to do that?

On Fri, Apr 18, 2014 at 2:13 AM, Scott Chamberlain <notifications@github.com

wrote:

Or at least for some people the hook only works when pressing knit html
button in rstudio.

Perhaps we need to edit the knit hook to make it work in any context.


Reply to this email directly or view it on GitHubhttps://github.com//issues/12
.

@nacnudus
Copy link

When knitting from the command line, interactive() is true.

pub$ggplotly <- function(gg=last_plot()){
    if(!is.ggplot(gg)){
      stop("gg must be a ggplot")
    }
    pargs <- gg2list(gg)
    if(interactive()){ # we are on the command line.
      resp <- do.call(pub$plotly, pargs)
      browseURL(resp$url)
      invisible(list(data=pargs, response=resp))
    }else{ # we are in knitr/RStudio.
      do.call(pub$iplot, pargs)
    }
  }

Not sure how to get around this. Interactivity seems to be a property of the session. Is it possible to create a new non-interactive session from within the console?

@ouzor
Copy link

ouzor commented Nov 10, 2014

I can not get the embedded iframes to work, tried both RStudio's 'knit html' button and knit(). Trying to replicate this: http://ropensci.org/blog/2014/04/17/plotly/.
Here's my sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] digest_0.6.4 htmltools_0.2.6 rmarkdown_0.3.10 tools_3.1.1 yaml_2.1.13

@mkcor
Copy link
Contributor

mkcor commented Nov 14, 2014

Hello @ouzor !

Follow the syntax below when writing your .Rmd file:

plotly_knitr

You want to set the session parameter to "knitr" in the ggplotly() call and also add the plotly=TRUE option in the code chunk where you embed a Plotly plot.

Hope this helps!

@mkcor
Copy link
Contributor

mkcor commented Nov 14, 2014

@ouzor Note that after clicking "Knit HTML" I also had to "Open in Browser" in order to see the embedded Plotly plot. The plot was generated (you can check online in your Plotly account), it's just a rendering thing.

@ouzor
Copy link

ouzor commented Nov 15, 2014

Thanks @mkcor, this works! I was not able to find much documentation for the ggplotly command, is that available somewhere?

@mkcor
Copy link
Contributor

mkcor commented Dec 30, 2014

@ouzor We are indeed behind with respect to documentation.
Now this is documented here: http://blog.plot.ly/post/106630252117/plot-with-ggplot2-and-plotly-within-knitr-reports
Thank you for your patience!

@mkcor mkcor closed this as completed Dec 30, 2014
@ouzor
Copy link

ouzor commented Jan 11, 2015

Thanks!
I made a short comparison of different interactive visualization packages in R, including plotly, see here: http://ouzor.github.io/blog/2014/11/21/interactive-visualizations.html
I like very much the idea of turning an existing ggplot2 object to a nice interactive version. However, as a data scientist I work a lot with confidential data and can not make any of that public, which to me seems that I can not use the free version of plotly at all...

@mkcor
Copy link
Contributor

mkcor commented Jan 14, 2015

Hi @ouzor

We definitely understand that’s a concern. Thanks for asking. A couple thoughts.

You control the privacy of your data, and can make your work public or keep it private (like Google Docs or GitHub).

You own your data; we don’t make an IP claim to it. We also have an on-premise version of plotly you can run on your own servers. Would any of these options work? Let me know if we can help with anything.

@ouzor
Copy link

ouzor commented Jan 16, 2015

Thanks a lot @mkcor, I'll take a closer look at these options!

@makis23
Copy link

makis23 commented Nov 28, 2015

why does this not work??
library(shiny)
library(plotly)

Rely on the 'WorldPhones' dataset in the datasets

package (which generally comes preloaded).

library(datasets)

Define a server for the Shiny app

shinyServer(function(input, output) {

Fill in the spot we created for a plot

output$phonePlot <- renderPlotly({

# Render a barplot

gg <- barplot(WorldPhones[,input$region]*1000,
main=input$region,
ylab="Number of Telephones",
xlab="Year")
})

p <- ggplotly(gg,session="knitr")
p
})

@aniruhil
Copy link

Despite following @mkcor's fix that seemed to work for @ouzor, I run into the listed error msg when running Knit HTML and when executing the code line-by-line from inside RStudio.

require(ggplot2)
gg <- ggplot(cars) + geom_point(aes(speed, dist))
gg

require(plotly)
py <- plotly("aniruhil", "maskedkey")
py$ggplotly(gg, session="knitr")
Quitting from lines 27-30 (testingplotly.Rmd) Error in eval(expr, envir, enclos) : attempt to apply non-function Calls: ... handle -> withCallingHandlers -> withVisible -> eval -> eval Execution halted

@cpsievert
Copy link
Collaborator

The interface has changed quite a bit since this thread first started. You should only need this:

library(plotly)
gg <- ggplot(cars) + geom_point(aes(speed, dist))
ggplotly(gg)

@aniruhil
Copy link

thanks Carson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants