1

I need some help in using event_data in plotly r to render a dataTable instead of just showing the cwrevenumber and 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')
    })    
3
  • your example is not reproducible; we can't run your code. Commented Apr 25, 2016 at 11:40
  • @MLavoie, thanks for taking time to look at my issue. Basically what I am trying to know is, if we use the choropleth example in plotly r, can we click o the country and produce a table shows data from the plot using event_data. Commented Apr 30, 2016 at 17:56
  • the event_data will have only information for the selected point, you need to retrieve your data and publish it if you want to see it as a table. Commented Mar 16, 2018 at 3:25

1 Answer 1

1

I think you missed the 'else' argument

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
})    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.