Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use plotly in R shiny

I am trying to add graph for the output which i have generated using shiny. I am getting error for graph generation. Can someone please have a look and assist. The bar graph parameters are calculation based outputs generated from calculations.

server
output$graph<- renderPlotly({

  plotly( x= c(as.numeric(input$contract), round(frateperton()), differencerate()),

         y= c('Contract Rate', 'ZBC Rate', 'Difference'),

         name = "Zero Based Rate Chart",

         type = "bar")

})


UI
plotlyOutput("graph"),

like image 232
mayank14 Avatar asked Dec 01 '22 09:12

mayank14


1 Answers

First of all, two remarks on your post :

  • it is not reproducible, see here to learn what a reproducible example is and how to make one
  • clearly you haven't searched enough. Typing "r shiny plotly output" in any search engine gives several potential solutions (here for example).

To avoid duplicated posts, please consider these two points next time.

Now, here's the answer (using iris data since your example is not reproducible):

library(shiny)
library(plotly)

ui <- fluidPage(
  selectInput("choice", "Choose", choices = names(iris), selected = NULL),
  plotlyOutput("graph")
  )

server <- function(input, output, session){
  
  output$graph <- renderPlotly({
    plot_ly(iris, x = ~get(input$choice), y = ~Sepal.Length, type = 'scatter', mode = 'markers')
  })
}

shinyApp(ui, server)
like image 63
bretauv Avatar answered Dec 04 '22 00:12

bretauv