7

I have created a shiny app to show a correlation heatmap for a large dataset. When the heatmap tiles are pressed, the corresponding scatterplots are displayed.

However, I need to make several of these apps and this exceeds my limit of publishing on shinyapps.io. My company is unwilling to upgrade to a paying plan. I have tried using alternative methods to publish the app such as RInno, to no avail (I think the app is too complex?).

If someone could please tell me how I could produce the same with plotly alone and NOT with shiny, I would be forever grateful. I believe something like crosstalk might be the path to take in order to link the heat map tiles to the scatter plots?

Thank you

Example from here.

library(plotly)
library(shiny)

# compute a correlation matrix
correlation <- round(cor(mtcars), 3)
nms <- names(mtcars)

ui <- fluidPage(
  mainPanel(
    plotlyOutput("heat"),
    plotlyOutput("scatterplot")
  ),
  verbatimTextOutput("selection")
)

server <- function(input, output, session) {
  output$heat <- renderPlotly({
    plot_ly(x = nms, y = nms, z = correlation, 
            key = correlation, type = "heatmap", source = "heatplot") %>%
      layout(xaxis = list(title = ""), 
             yaxis = list(title = ""))
  })

  output$selection <- renderPrint({
    s <- event_data("plotly_click")
    if (length(s) == 0) {
      "Click on a cell in the heatmap to display a scatterplot"
    } else {
      cat("You selected: \n\n")
      as.list(s)
    }
  })

  output$scatterplot <- renderPlotly({
    s <- event_data("plotly_click", source = "heatplot")
    if (length(s)) {
      vars <- c(s[["x"]], s[["y"]])
      d <- setNames(mtcars[vars], c("x", "y"))
      yhat <- fitted(lm(y ~ x, data = d))
      plot_ly(d, x = ~x) %>%
        add_markers(y = ~y) %>%
        add_lines(y = ~yhat) %>%
        layout(xaxis = list(title = s[["x"]]), 
               yaxis = list(title = s[["y"]]), 
               showlegend = FALSE)
    } else {
      plotly_empty()
    }
  })

}

shinyApp(ui, server)

enter image description here

J.Con
  • 4,101
  • 4
  • 36
  • 64
  • 1
    I don't really understand what you want to do but couldn't it be solution to put that what you call different apps in multiple tabs? In that way you are still just publishing one app in shinyapp.io! – Bertil Baron May 14 '18 at 07:39
  • @BertilBaron thanks for the idea but there are also only limited usage hours available in the free shinyapps.io, making any shiny app non-viable for our purposes. – J.Con May 14 '18 at 07:41
  • 2
    what about hosting on your own server with the opensource shiny-server then you can host as many apps you want and you have no limited usage hours. Just an Idee. To host a server would be much cheaper than to have you all learning a new technology and you already have quite a nice app in Shiny – Bertil Baron May 14 '18 at 07:46
  • @BertilBaron thank you again but doesn’t that require linux? I am not technologically advanced enough to wrangle it! – J.Con May 14 '18 at 08:02
  • 1
    to follow BertilBaron idea, you could also rent a server on Amazon Web Services (aws-EC2). It is relatively simple to install the shiny-server. – MLavoie May 14 '18 at 10:35
  • @MLavoie thanks for the suggestion. I guess all I can do is try. – J.Con May 14 '18 at 22:13
  • 1
    You could wrap your app in a docker container and host it via shinyproxy: https://www.shinyproxy.io – ismirsehregal Oct 18 '18 at 20:20
  • 1
    On Windows even easier is running the script as a service: add runApp(host="0.0.0.0", port=80) to your app, configure RScript.exe as target and add your script as an argument via: https://nssm.cc – ismirsehregal Oct 18 '18 at 20:46

1 Answers1

1

The best answer would likely be to use crosstalk in conjunction with flexdashboard https://rmarkdown.rstudio.com/flexdashboard/.

A live example of using both be found here: http://rstudio-pubs-static.s3.amazonaws.com/209203_02f14fea3274448bbbf8d04c99c6051b.html.

The end result is just an html page which is easy to share and use. Based on your example you shouldn't need shiny and it you should be able to use crosstalk for this use case. You'd need to step outside of R to get that functionality otherwise. Best of luck!

Bryant
  • 13
  • 1
  • 3