Narayan Wagh
Narayan Wagh

Reputation: 41

How to display/send r plotly plots on web using plumber?

I have one plotly plot and I want to display plot on other UI such as angular, using R Plumber.

Upvotes: 4

Views: 1131

Answers (1)

Abhishek R
Abhishek R

Reputation: 4763

Here is how you do it:

# API for experimenting with html widgets

library(plumber)
library(ggplot2)
library(plotly)

#* @apiTitle HTML widgets API

#* Return interactive plot using plotly
#* @serializer htmlwidget
#* @get /plotly
function() {
  p <- ggplot(data = diamonds,
              aes(x = cut, fill = clarity)) +
    geom_bar(position = "dodge")

  ggplotly(p)
}

Hope this helps.

Source - https://github.com/blairj09/plumber-playground/blob/master/experiments/htmlwidgets-exp/plumber.R

Upvotes: 5

Related Questions