【问题标题】:Use event_data from map in Plotly R to render dataTable在 Plotly R 中使用 map 中的 event_data 来渲染 dataTable
【发布时间】:2016-04-24 18:00:08
【问题描述】:

我需要一些帮助来使用 plotly r 中的 event_data 来呈现数据表,而不仅仅是显示 cwrevenumber 和 pointNumber。

    output$plot1 <- renderPlotly({
    df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')    

    # light grey boundaries
     l <- list(color = toRGB("grey"), width = 0.5)

    # specify map projection/options
    g <- list(
      showframe = FALSE,
      showcoastlines = FALSE,
      projection = list(type = 'Mercator')
      )

      plot_ly(df, z = GDP..BILLIONS., text = COUNTRY, locations = CODE, type =       'choropleth', source = 'click', color = GDP..BILLIONS., colors = 'Blues', marker =     list(line = l),
        colorbar = list(tickprefix = '$', title = 'GDP Billions US$')) %>%
  layout(title = '2014 Global GDP<br>Source:<a href="https://www.cia.gov/library/publications/the-world-factbook/fields/2195.html">CIA World Factbook</a>',
         geo = g)
    })


output$c_locate_info <- renderDataTable({
    event.data <- event_data(event='plotly_click', source = 'click') 

    if(is.null(event.data)==T) return('Select Regions for More Details')
    })    

【问题讨论】:

  • 您的示例不可重现;我们无法运行您的代码。
  • @MLavoie,感谢您花时间查看我的问题。基本上我想知道的是,如果我们在 plotly r 中使用 choropleth 示例,我们可以单击国家并生成一个表格,使用 event_data 显示来自情节的数据。
  • event_data 将仅包含所选点的信息,如果您想将其作为表格查看,则需要检索数据并发布。

标签: r shiny plotly


【解决方案1】:

我认为你错过了 'else' 参数

output$c_locate_info <- renderDataTable({
event.data <- event_data(event='plotly_click', source = 'click') 

if(is.null(event.data)==T) return('Select Regions for More Details') else d
})    

【讨论】:

    猜你喜欢
    • 2018-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 2019-12-18
    • 2019-10-18
    • 1970-01-01
    • 2020-10-10
    相关资源
    最近更新 更多