【发布时间】:2018-10-09 01:38:06
【问题描述】:
我正在使用 jQuery (jQuery Core 2.1.4) 开发我的 Shiny 应用程序的一部分。此外,我正在使用新的plotly 包来渲染绘图。 jQuery 可以独立运行,plotly 也可以;但是,当同时使用两者时,来自plotly 的图消失了。调用 jQuery 似乎是原因。
是否有允许使用 jQuery 和
plotly的解决方法 (特别是ggplotly)在同一个闪亮的应用程序中?
这是一个例子。我知道这个例子不需要 jQuery,而只是为了说明 plotly 在包含 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 取消
#tags$head(tags$script(src='http://code.jquery.com/jquery-2.1.4.js')),行的注释,你会发现它消失了(至少在 R 的浏览器和 Chrome 中) -
请看我的解决方案。你还有什么期待的吗?
-
就是这样。谢谢! (以及解释)