R Plotly版本4.9.0中的plotly_click错误。新版本中有错误吗?

标记

更新3:带有dropdownbutton问题的新测试应用

library(shiny)
library(shinydashboard)
library(plotly)
library(shinyWidgets)

rm(list = ls(), envir = environment()) ## to prevent cross over from old runs

testData = data.frame(day = sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 24), frequency = sample(1:5, 24, replace = T ), datecoloring = sample(1:2, 24, replace = T ))
testData$dayPOSIXct <- as.POSIXct(testData$day)

dateRangeMin <- min(testData$day)
dateRangeMax <- max(testData$day)




  ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar( 
      menuItem("Testpage", tabName = "Testpage", icon = icon("home"))
                      ),
    dashboardBody( 
      tabItems(
        # 1) Test Tab ---------------------------------------------------------------

        tabItem(tabName = "Testpage",
            actionButton(inputId = 'Load', label = 'Data'),
            dropdownButton(inputId= "TestButton", label = NULL,
              plotlyOutput('testplot', width = 700, height = 500),
              icon = icon("list-alt"), 
              tooltip = tooltipOptions(title = "Click to open and render the plot"), width = "1670px")

        )
      )
      ),
    title = "Dashboard example"
  )


server <- function(input, output,session) {

  values <- reactiveValues()

  observeEvent(input$Load, { 
    values$testData <- testData
  })

  output$testplot <- renderPlotly({
    req(values$testData)
    p <-  plot_ly(data = values$testData, source = 'testplot',
                  color  = as.factor(values$testData$datecoloring), colors = c('#339fff', '#eaf5ff'),
                  opacity= 0.5, showlegend = T,
                  marker = list(line = list(width = 2, color = '#0000ff')),
                  hoverinfo = "text",
                  text = ~paste('Files:', values$testData$frequency, '<br>Date:', format(values$testData$day, format = '%Y-%m-%d'), sep = ' '))%>%
      add_bars( x = ~dayPOSIXct, y =  ~frequency,   type = "bar", width = 36000000
      )

    p
  })

  relayout_data <- reactive({
    req(values$testData)
    event_data("plotly_relayout", source = "testplot")
  })

  observeEvent(relayout_data(),{
    print(relayout_data())
  })  
}
shinyApp(ui, server)

更新2:可以通过正确使用req()或不使用对event_data进行观察的代码与对event_data进行某些操作的代码分离的方法来解决该问题。如:

relayout_data <- reactive({
req(values$testData)
event_data("plotly_relayout", source = "testplot")


 })

  observeEvent(relayout_data(),{
    print(relayout_data())
  })

但是,对于情节在内部的情况,即下拉按钮面板或发光应用程序的其他选项卡/页面,这似乎无法提供解决方案。加载绘图所需的数据后,将满足req()并将激发代码,但由于当前屏幕中未显示该绘图,因此仍未呈现该绘图。

更新:这个问题也报告在github上,目前还没有真正的解决方案 https://github.com/ropensci/plotly/issues/1528

原始问题/帖子:

今天,我更新了R中的所有程序包,突然我得到了很多错误,这些错误来自于R闪亮的App中R中的新版4.9.0版本。

所有这些错误均参考plotly_relayoutplotly_click等等。

警告:与源ID“ DateRangeHisto”绑定的“ plotly_relayout”事件未注册。为了获取此事件数据,请添加event_register(p, 'plotly_relayout')p您希望从中获取事件数据的图()。

我试图以各种方式添加event_register,但没有效果。我想新版本中有错误吗?

这是一个无聊的虚拟应用程序,该应用程序产生了带有4.9.0的错误并更新了所有软件包。

更新:尽管req()内部没有可用的绘图plot_ly数据,似乎发生event_data了错误,这会导致错误。以前的plotly版本并没有发生这种情况。所以,现在如何解决这个问题

    library(shiny)
    library(plotly)



rm(list = ls(), envir = environment()) ## to prevent cross over from old runs

testData = data.frame(day = sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 24), frequency = sample(1:5, 24, replace = T ), datecoloring = sample(1:2, 24, replace = T ))
testData$dayPOSIXct <- as.POSIXct(testData$day)

dateRangeMin <- min(testData$day)
dateRangeMax <- max(testData$day)
if(!require('shiny')){ install.packages('shiny', dependencies=TRUE)}
if(!require('shinyWidgets')){ install.packages('shinyWidgets', dependencies=TRUE)}
if(!require('plotly')){ install.packages('plotly', dependencies=TRUE)}
if(!require('htmlwidgets')){ install.packages('htmlwidgets')}


ui <- fluidPage(
  actionButton(inputId = 'Load', label = 'Data'),
  plotlyOutput('testplot', width = 700, height = 500)

)


server <- function(input, output,session) {

  values <- reactiveValues()

  observeEvent(input$Load, { 
    values$testData <- testData
    })

  output$testplot <- renderPlotly({ 
    req(values$testData)
    p <-  plot_ly(data = values$testData, source = 'testplot',
                  color  = as.factor(values$testData$datecoloring), colors = c('#339fff', '#eaf5ff'),
                  opacity= 0.5, showlegend = T,
                  marker = list(line = list(width = 2, color = '#0000ff')),
                  hoverinfo = "text",
                  text = ~paste('Files:', values$testData$frequency, '<br>Date:', format(values$testData$day, format = '%Y-%m-%d'), sep = ' '))%>%
      add_bars( x = ~dayPOSIXct, y =  ~frequency,   type = "bar", width = 36000000
      )
    p
  })

  observeEvent(event_data("plotly_relayout", source = "testplot"),{
    #any code here, doesn't matter, bug happens already
  })


}

shinyApp(ui, server)

会话信息

sessionInfo()
R version 3.5.3 (2019-03-11)
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=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252    LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C                       LC_TIME=Dutch_Netherlands.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_4.9.0  ggplot2_3.1.1 shiny_1.3.2  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1         pillar_1.4.0       compiler_3.5.3     later_0.8.0        colourpicker_1.0.3 plyr_1.8.4         shinyjs_1.0        tools_3.5.3        digest_0.6.19      viridisLite_0.3.0 
[11] jsonlite_1.6       tibble_2.1.1       gtable_0.3.0       pkgconfig_2.0.2    rlang_0.3.4        rstudioapi_0.10    crosstalk_1.0.0    yaml_2.2.0         httr_1.4.0         withr_2.1.2       
[21] dplyr_0.8.1        htmlwidgets_1.3    grid_3.5.3         DT_0.6             tidyselect_0.2.5   glue_1.3.1         data.table_1.12.2  R6_2.4.0           tidyr_0.8.3        purrr_0.3.2       
[31] magrittr_1.5       scales_1.0.0       promises_1.0.1     htmltools_0.3.6    assertthat_0.2.1   mime_0.6           xtable_1.8-4       colorspace_1.4-1   httpuv_1.5.1       miniUI_0.1.1.1    
[41] lazyeval_0.2.2     munsell_0.5.0      crayon_1.3.4    
伊斯米尔谢尔夫

问题在于,observeEvent正在尝试event_data渲染图形之前访问您也可以req()针对来解决此问题event_data()确实,在4.9.0上确实对此更为严格。

library(shiny)
library(shinydashboard)
library(plotly)
library(shinyWidgets)

rm(list = ls(), envir = environment()) ## to prevent cross over from old runs

testData = data.frame(day = sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 24), frequency = sample(1:5, 24, replace = T ), datecoloring = sample(1:2, 24, replace = T ))
testData$dayPOSIXct <- as.POSIXct(testData$day)

dateRangeMin <- min(testData$day)
dateRangeMax <- max(testData$day)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Testpage", tabName = "Testpage", icon = icon("home"))
    )
  ),
  dashboardBody( 
    tabItems(
      # 1) Test Tab ---------------------------------------------------------------

      tabItem(tabName = "Testpage",
              actionButton(inputId = 'Load', label = 'Data'),
              dropdownButton(inputId = "TestButton", label = NULL,
                             plotlyOutput('testplot', width = 700, height = 500),
                             icon = icon("list-alt"), 
                             tooltip = tooltipOptions(title = "Click to open and render the plot"), width = "1670px")

      )
    )
  ),
  title = "Dashboard example"
)


server <- function(input, output, session) {

  # output$testplot <- renderPlotly({plot_ly(data.frame(NULL), source = 'testplot')})

  values <- reactiveValues()

  observeEvent(input$Load, {
    values$testData <- testData
  })

  output$testplot <- renderPlotly({
    req(values$testData)
    p <-  plot_ly(data = values$testData, source = 'testplot',
                  color  = as.factor(values$testData$datecoloring), colors = c('#339fff', '#eaf5ff'),
                  opacity= 0.5, showlegend = T,
                  marker = list(line = list(width = 2, color = '#0000ff')),
                  hoverinfo = "text",
                  text = ~paste('Files:', values$testData$frequency, '<br>Date:', format(values$testData$day, format = '%Y-%m-%d'), sep = ' '))%>%
      add_bars( x = ~dayPOSIXct, y =  ~frequency,   type = "bar", width = 36000000)
    p 
  })

  relayout_data <- reactive({
    req(values$testData)
    req(input$TestButton_state)
    event_data("plotly_relayout", source = "testplot")
  })

  observeEvent(relayout_data(),{
    print(relayout_data())
  })  
}
shinyApp(ui, server)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Debian 9停止在新版本中并没有真正关闭电源-为什么?

不推荐使用WebViewClient onReceivedError,新版本无法检测所有错误

R plotly版本4.5.2散点图例气泡大小设置

APP_INITIALIZER 导致空白页,在 Angular 12 中没有错误(从版本 9 到 11)

新版本云9:如何部署到heroku

最新版本在 r 中的位置

安装新版本R的无痛方法?

让R使用Java的较新版本

致命错误编译:无效的目标版本:9

如何在R Shiny中显示plotly_click中的许多点?

Xcode 9发行版本构建失败,因为新版本中exportOptions.plist的格式已更改

如何在plotly的更新版本中设置布局?

“设备已具有较新版本”错误

XAMPP的新版本给出错误而没有消息

Plotly(在R中)关于“标记”的错误消息

SPARK错误:服务器IPC版本9无法与客户端版本4通信

有什么新版本的Weinre吗?

为什么某些R软件包不更改新版本中的版本号

在 R 和 plotly 中使用 plotly_click 更新多个信息框

我在selenuim中遇到错误。我拥有最新版本的Chrome:87.0.4280.66。Selenuim Chrome版本:87

Java:无效的源版本:9

版本跟踪-错误与最新版本无关

gradlew 包装器更新到新版本错误,您有旧版本

如何获取最新版本的 acrobat reader(不是 acrobat reader 9)

如何最好地重新测试更新版本或开发版本中的错误?

Django+Bootstrap4 引发错误:“需要 mysqlclient 1.4.0 或更新版本;您有 0.10.0。”

无法安装R包的最新版本

我无法安装最新版本的 R

在R中安装最新版本的xgboost时出错