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