Giter VIP home page Giter VIP logo

Comments (14)

ouzor avatar ouzor commented on August 23, 2024 1

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

from plotly.r.

mkcor avatar mkcor commented on August 23, 2024 1

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!

from plotly.r.

tdhock avatar tdhock commented on August 23, 2024

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 <[email protected]

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
.

from plotly.r.

nacnudus avatar nacnudus commented on August 23, 2024

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?

from plotly.r.

mkcor avatar mkcor commented on August 23, 2024

@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.

from plotly.r.

ouzor avatar ouzor commented on August 23, 2024

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

from plotly.r.

mkcor avatar mkcor commented on August 23, 2024

@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!

from plotly.r.

ouzor avatar ouzor commented on August 23, 2024

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...

from plotly.r.

mkcor avatar mkcor commented on August 23, 2024

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.

from plotly.r.

ouzor avatar ouzor commented on August 23, 2024

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

from plotly.r.

makis23 avatar makis23 commented on August 23, 2024

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
})

from plotly.r.

aniruhil avatar aniruhil commented on August 23, 2024

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

from plotly.r.

cpsievert avatar cpsievert commented on August 23, 2024

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)

from plotly.r.

aniruhil avatar aniruhil commented on August 23, 2024

thanks Carson

from plotly.r.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.