Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. library(plotly)
  2. library(shiny)
  3.  
  4. ui <- fluidPage(
  5. plotlyOutput("plot"),
  6. verbatimTextOutput("click1")
  7. )
  8.  
  9. server <- function(input, output, session) {
  10.  
  11. output$plot <- renderPlotly({
  12. p1 <- plot_ly(mtcars, x = ~mpg, y = ~wt, yaxis='y')
  13. p2 <- plot_ly(mtcars, x = ~mpg, y = ~wt, yaxis='y2')
  14. p1 <- layout(p1, yaxis=list(title="% growth",
  15. scaleanchor='y2', constraintoward='bottom'),
  16. xaxis=list(domain=c(0, 1)))
  17. p2 <- layout(p2, yaxis=list(title="% loss", autorange='reversed',
  18. scaleanchor='y', constraintoward='top'),
  19. xaxis=list(domain=c(0, 1)))
  20. p <- subplot(p1, p2, nrows=2,
  21. shareX=TRUE, titleX=TRUE,
  22. shareY=FALSE, titleY=TRUE,
  23. margin=0.02)
  24. p <- layout(p, xaxis = list(domain=c(0,1)), legend=list(orientation='h'))
  25. p
  26. #browser()
  27. })
  28.  
  29. output$click1 <- renderPrint({
  30. d <- event_data("plotly_click")
  31. if (is.null(d)) "Click events appear here" else d
  32. })
  33.  
  34. }
  35.  
  36. shinyApp(ui, server)
  37.  
  38. Warning: Can only have one: source
  39. Warning: Can only have one: config
  40. Warning: Can only have one: highlight
  41.  
  42. > sessionInfo()
  43. R version 3.4.4 (2018-03-15)
  44. Platform: x86_64-w64-mingw32/x64 (64-bit)
  45. Running under: Windows 7 x64 (build 7601) Service Pack 1
  46.  
  47. Matrix products: default
  48.  
  49. locale:
  50. [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
  51. [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
  52. [5] LC_TIME=English_United Kingdom.1252
  53.  
  54. attached base packages:
  55. [1] stats graphics grDevices utils datasets methods base
  56.  
  57. other attached packages:
  58. [1] bindrcpp_0.2 corrplot_0.84 shinythemes_1.1.1 leaflet_1.1.0
  59. [5] reshape_0.8.6 knitr_1.21 markdown_0.9 htmltools_0.3.6
  60. [9] plotly_4.8.0 shinyWidgets_0.4.4 ggplot2_3.1.0 shiny_1.2.0
  61.  
  62. loaded via a namespace (and not attached):
  63. [1] Rcpp_0.12.18 pillar_1.3.0 compiler_3.4.4 later_0.7.5
  64. [5] plyr_1.8.4 bindr_0.1 tools_3.4.4 digest_0.6.12
  65. [9] viridisLite_0.3.0 jsonlite_1.5 tibble_1.4.2 gtable_0.2.0
  66. [13] pkgconfig_2.0.1 rlang_0.3.1 rstudioapi_0.9.0 crosstalk_1.0.0
  67. [17] yaml_2.2.0 xfun_0.4 withr_2.1.2 dplyr_0.7.4
  68. [21] httr_1.3.1 sourcetools_0.1.6 htmlwidgets_1.3 grid_3.4.4
  69. [25] glue_1.3.0 data.table_1.10.4-3 R6_2.2.0 tidyr_0.8.2
  70. [29] purrr_0.2.4 magrittr_1.5 scales_1.0.0 promises_1.0.1
  71. [33] rsconnect_0.8.5 assertthat_0.2.0 mime_0.5 xtable_1.8-2
  72. [37] colorspace_1.3-2 httpuv_1.4.5.1 labeling_0.3 lazyeval_0.2.0
  73. [41] munsell_0.5.0 crayon_1.3.4 Cairo_1.5-9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement