Show Sidebar Hide Sidebar

Shiny app using Plotly in R

Shiny app to explore Movies dataset

Shiny app

Code

ui.r

library(shiny)
library(plotly)

shinyUI(fluidPage(
  titlePanel("Movie Ratings!"),
  sidebarPanel(
    sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 10)
  ),
  mainPanel(
    plotlyOutput("trendPlot")
  )
))

server.r

library(shiny)
library(plotly)
library(ggplot2movies) # movies is no longer contained within ggplot2 https://cran.r-project.org/web/packages/ggplot2movies/index.html

minx <- min(movies$rating)
maxx <- max(movies$rating)

shinyServer(function(input, output) {

  output$trendPlot <- renderPlotly({
    # size of the bins depend on the input 'bins'
    size <- (maxx - minx) / input$bins

    # a simple histogram of movie ratings
    p <- plot_ly(movies, x = rating, autobinx = F, type = "histogram",
                 xbins = list(start = minx, end = maxx, size = size))
    # style the xaxis
    layout(p, xaxis = list(title = "Ratings", range = c(minx, maxx), autorange = F,
                           autotick = F, tick0 = minx, dtick = size))
  })
})
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.