I am using jQuery (jQuery Core 2.1.4) to develop part of my Shiny app. In addition, I am using the new plotly
package to render the plots. jQuery works perfectly on its own and plotly
too; however when using both, the plots from plotly
dissapear. Calling jQuery seems to be the cause.
Is there a work-around that allows to use jQuery and
plotly
(specificallyggplotly
) in the same Shiny App?
Here is an example. I am aware this example does not need the jQuery but is only to illustrate how plotly
plots dissapear when including jQuery (uncomment the line #tags$head(tags$script(src='http://code.jquery.com/jquery-2.1.4.js')),
to include it):
#Call the required libraries
library(shiny)
library(plotly)
library(ggplot2)
#Server to output plot
server <- shinyServer(function(input, output) {
output$plotlyout <- renderPlotly({
#Create random points
x <- rnorm(100)
y <- rnorm(100)
#Set to data frame
dats <- as.data.frame(cbind(x,y))
#Plot them in plotly
ggplotly(ggplot(dats) + geom_point(aes(x = x, y = y)))
})
})
#Shiny plot
ui <- shinyUI(
#One page with main Panel
fluidPage(
#Uncomment this to see how Jquery ruins everything
#tags$head(tags$script(src='http://code.jquery.com/jquery-2.1.4.js')),
#Panel for plot
mainPanel(
#Output plot
plotlyOutput("plotlyout")
)
)
)
shinyApp(ui = ui, server = server, options = list(launch.browser = TRUE))
Thanks!