Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. ui <- fluidPage(
  2.  
  3. radioButtons("plotType", "Plot Type:", choices = c("ggplotly", "plotly")),
  4.  
  5. plotlyOutput("plot"
  6.  
  7. ),
  8.  
  9. verbatimTextOutput("click"),
  10.  
  11. verbatimTextOutput("brush")
  12.  
  13. )
  14.  
  15. server <- function(input, output, session) {
  16.  
  17. output$plot <- renderPlotly({
  18.  
  19. # use the key aesthetic/argument to help uniquely identify selected observations
  20.  
  21. key <- row.names(mtcars)
  22.  
  23. if (identical(input$plotType, "ggplotly")) {
  24.  
  25. p <- ggplot(data, aes(x = c(1:nrow(data)) , y = y, colour = factor(WF_ID), key = LOT_CODE)) +
  26.  
  27. geom_line(color="black") + geom_point()
  28.  
  29. ggplotly(p) %>% layout(dragmode = "select")
  30.  
  31. } else {
  32.  
  33. plot_ly(data, x = ~c(1:nrow(data)), y = ~y, key = ~data$LOT_CODE, mode = 'lines+markers') %>%
  34.  
  35. layout(dragmode = "select")
  36.  
  37. }
  38.  
  39. })
  40.  
  41. output$click <- renderPrint({
  42.  
  43. d <- event_data("plotly_click")
  44.  
  45. if (is.null(d)) "Click events appear here (double-click to clear)" else d
  46.  
  47. })
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement