for loop - R: Profvis doesn't show any results -
i need fix code faster. i've reading , i've been introduced profvis
package.
the thing works in excercise not real code.
this excersice code i'm talking about:
library("profvis") profvis({ data(movies, package = "ggplot2movies") # load data movies = movies[movies$comedy == 1,] plot(movies$year, movies$rating) model = loess(rating ~ year, data = movies) # loess regression line j = order(movies$year) lines(movies$year[j], model$fitted[j]) # add line plot })
and code (the 1 need optimize): profvis
shows blank screen.
library("profvis") library(rselenium) library(rvest) library(dplyr) library(stringr) library(urltools) #start rselenium rd <- rsdriver(port = 4506l, browser = "firefox", version = "latest", chromever = "latest", geckover = "latest", iedrver = null, phantomver = "2.1.1", verbose = true, check = true) remdr <- rd[["client"]] ### urls ### falabella_urls <- c("http://www.falabella.com.pe/falabella-pe/category/cat7230497/accesorios-hombre?no=0&nrpp=1000", "http://www.falabella.com.pe/falabella-pe/category/cat7230497/accesorios-hombre?no=1000&nrpp=1000") ############################# testaaa <- function() { falabella_data_list <- list() (i in falabella_urls$url[1:2]) { remdr$navigate(i) print(i) sys.sleep(05) page_source<-remdr$getpagesource() product_info <- function(node){ subcategoria_url <- str_split(path(i), "\\/")[[1]][4] s.marca <- html_nodes(node,"div.marca a") %>% html_text s.producto <- html_nodes(node,"div.detalle a") %>% html_attr("href") s.precio.antes <- html_nodes(node, "div.precio2 span") %>% html_text s.precio.actual <- html_nodes(node, "div.precio1 span") %>% html_text data.frame( fecha = as.character(sys.date()), subcategoria = subcategoria_url, ecommerce = "falabella", marca = s.marca, producto = s.producto, precio.antes = ifelse(length(s.precio.antes) == 0, na, s.precio.antes), precio.actual = ifelse(length(s.precio.actual) == 0, na, s.precio.actual), stringsasfactors=f ) } doc <- read_html(iconv(page_source[[1]]), to="utf-8") %>% html_nodes(".cajalp4x") productos <- lapply(doc, product_info) %>% bind_rows() falabella_data_list[[i]] <- productos # add list } falabella = do.call(rbind, falabella_data_list) } profvis({testaaa()})
Comments
Post a Comment