我正在使用jQuery (jQuery Core 2.1.4)開發我的Shiny應用程序的一部分。另外,我正在使用新的plotly
包來渲染圖。 jQuery自己也完美工作,並且plotly
也是;然而,當使用兩者時,來自plotly
的地塊消失。調用jQuery似乎是原因。當在R中使用jQuery時Plotly消失
是否有變通,允許在同一個閃亮的應用程序使用jQuery和
plotly
(特別ggplotly
)?
這裏是一個例子。我知道這個例子不需要jQuery的,但只是爲了說明plotly
情節如何dissapear包括jQuery的時候(註釋該行#tags$head(tags$script(src='http://code.jquery.com/jquery-2.1.4.js')),
包括它):
#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))
謝謝!
「但只是爲了說明如何陰謀詭計消失」......你是什麼意思?當我運行你的代碼,我得到了陰謀...... – MLavoie
@MLavoie取消註釋行#標籤$頭(標籤$ script(src ='http://code.jquery.com/jquery-2.1.4.js' )),然後你就會消失(至少在R的瀏覽器和Chrome中) –
請看我的解決方案。還有什麼你期望的? –