3

I have a plotly based graph in R and I wish to display it on my github pages. I am not able to display the graph when I convert into to markdown. I was able to render an html of plotly plot, but I dont know how to use with pages.Here is my rep and file for the below markdown

library(XML)
library(ggplot2)
library(tidyr)
library(dplyr)
library('maps')
library('ggthemes')
library('plotly')

A_loc<-tbl_df(readLines("https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat"))
New_A_loc<-as.data.frame(sapply(A_loc, function(x) gsub("\"", "", x)))
New_A_loc<-separate(data = New_A_loc, col = value, into = c("Airport_id", "Name","City","Country","IATA","ICAO","Lat","Long","Alt","Timezone","DST","TZ","Type","Source"), sep = ",")
New_A_loc$Lat <- as.numeric(New_A_loc$Lat)

New_A_loc$Long <- as.numeric(New_A_loc$Long)
New_A_loc$Alt<-as.numeric(New_A_loc$Alt)
New_A_loc$Name<-as.character(New_A_loc$Name)

g <- list(showframe = FALSE,
  coastlinecolor = toRGB("white"),
  showland = TRUE,
  landcolor = toRGB("gray80"),
  showcountries = TRUE,
  countrycolor = toRGB("white"),
  countrywidth = 0.2,
  projection = list(type = 'Mercator'))


  plot_geo(New_A_loc, 
     lat = ~Lat, 
     lon = ~Long,
     text = ~City,
     mode='markers',
     marker = list(color = toRGB("purple"),
                   opacity = 0.5,
                   line = list(color = toRGB("purple"),
                               width = 0.5))
    ) %>%
    layout(geo = g) %>% htmlwidgets::saveWidget("New_2.html")
  • 1
    Markdown files can include valid html, so you should be able to just copy/paste the plotly html file contents into your markdown post. Alternatively, [this SO post](https://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file) may be helpful. – mikeck Aug 22 '17 at 05:59

0 Answers0