[英]No plot displayed with plotly in shiny
当我将https://plot.ly/r/shinyapp-plotly-events/ 中的代码粘贴到我的控制台中时,没有显示绘图图,我无法使用绘图显示任何闪亮的绘图。
我的会话信息:
R version 3.4.0 (2017-04-21)
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=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plotly_4.7.0 ggplot2_2.2.1.9000 feather_0.3.1 RODBC_1.3-15 dplyr_0.5.0 shiny_1.0.3
我是否使用了错误的软件包版本? 我从 cran 重新安装了所有东西,但我从来没有看到一个闪亮的情节图。 我可以在查看器中的 RStudio 内生成绘图图。 我是否必须使用 plotly/ggplot/shiny 的任何 devtools 版本或所有 devtool 版本? 我试过 plotly_4.7.0.9000 但仍然没有显示输出。
我发现一个 post plotly 图没有显示renderPlotly({return(plot_ly(x))}) 已损坏,但即使使用 renderPlotly(data) 我也无法生成任何闪亮的帧。
来自 plotly 画廊的示例代码,我想错误应该在我的设置中,作为代码的形式:
library(plotly)
library(shiny)
ui <- fluidPage(
radioButtons("plotType", "Plot Type:", choices = c("ggplotly", "plotly")),
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom")
)
server <- function(input, output, session) {
output$plot <- renderPlotly({
# use the key aesthetic/argument to help uniquely identify selected observations
key <- row.names(mtcars)
if (identical(input$plotType, "ggplotly")) {
p <- ggplot(mtcars, aes(x = mpg, y = wt, colour = factor(vs), key = key)) +
geom_point()
ggplotly(p) %>% layout(dragmode = "select")
} else {
plot_ly(mtcars, x = ~mpg, y = ~wt, key = ~key) %>%
layout(dragmode = "select")
}
})
output$hover <- renderPrint({
d <- event_data("plotly_hover")
if (is.null(d)) "Hover events appear here (unhover to clear)" else d
})
output$click <- renderPrint({
d <- event_data("plotly_click")
if (is.null(d)) "Click events appear here (double-click to clear)" else d
})
output$brush <- renderPrint({
d <- event_data("plotly_selected")
if (is.null(d)) "Click and drag events (i.e., select/lasso) appear here (double-click to clear)" else d
})
output$zoom <- renderPrint({
d <- event_data("plotly_relayout")
if (is.null(d)) "Relayout (i.e., zoom) events appear here" else d
})
}
shinyApp(ui, server)
非常欢迎任何建议,谢谢!
https://github.com/ropensci/plotly/issues/1042在 plotly 的 devtools 版本中修复了问题。
devtools::install_github('ropensci/plotly')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.