mayank14
mayank14

Reputation: 167

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"),

Upvotes: 11

Views: 25548

Answers (1)

bretauv
bretauv

Reputation: 8587

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
  • There are already several posts about this. 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)

Upvotes: 39

Related Questions