Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

plotly

plumber

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

like image 751
Narayan Wagh Avatar asked Sep 12 '25 00:09

Narayan Wagh


1 Answers

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

like image 71
Abhishek R Avatar answered Sep 14 '25 15:09

Abhishek R