Posts

Showing posts from 2017
Making an Asynchronous call inside a for loop in Angular 2 ------------------------------------------------------------------------ One of the frustrating problems of Angular 2, is that when you call an asynchronous method inside a for loop. It happens that, before the call returns for 1st iteration, the second iteration is called and this messes up the value of variables. Solution: One should use the flatMap here, to make sure that call from 2nd iteration does not happen unless call returns and completes for the 1st iteration. Observable . of ( localListID ). flatMap (( ellistId ) => ellistId ). subscribe (( pData ) => { //Make asynchronous call here, using pData. } Here localListID is array, and we want to use elements of this array to make asynchronous calls.
Some Html Issues faced while working with Angular 2. Checkbox not getting selected on Screen. --------------------------------------------------          Soultion: Changed the z-index of checkbox and moved it to the front. Only one checkbox getting selected. --------------------------------------------------         Solution: Added a handler on the click, sent the event to the handler, and called event.stopPropagation() inside handler.
Some useful Xpath expressions to extract correct element from Html/XML. --------------------------------------------------------------------------------- I faced many issues while trying to learn to write Xpath expressions when i was trying to parse correct elements from Html and XML documents. Here are some of the long and complex XPaths with their explanations. 1. xpathApply(doc,"//p[not(ancestor::footer[@class='footer footer-intl'])][not(@class='email-signup-description')]",xmlValue) Explanation: Get the value of those "p" nodes, which do not have "footer" ancestors with class aatributes value as "footer footer-intl" and which do not have "footer" ancestors with value of class attribute as "email-signup-description". 2. xpathSApply(doc,"//p[not(contains(@class,'promo__summary'))]", xmlValue) Explanation: Get the value of those "p" nodes, where value of "class&quo
Facebook extraction using R. ( For beginners of Facebook App development).  ---------------------------------------------------------------------------------------------- It took me lot of time to authenticate with Facebook when i was trying to extract data from facebook using Rfacebook package in R language. An important step which is not documented properly while authenticating our APP using R code. After creating the Application, Go to Settings and click on "add platform". Their you will find a textbox with name "Site URL"  fbOAuth(app_id = "XXXXXXXXXXXXXX",app_secret = "XXXXXXXXXXXXXXXXX") When we run above code, on console with get a small link. "http://localhost:1410/ ", This link has to be pasted in  Site URL text box in App settings and saved. After we do this, we should press "Enter" on the R console, which lets this API authenticate the APP on Facebook. Once this is done the APP is authenticate and a browse
Very important thing to remember while making RMarkdown file. --------------------------------------------------------------------------------- When coding the different r code chunks of a markdown file it is very intuitive and tempting to copy paste code from other chunks in the same file for similar analysis.  Please do not just copy paste codes from other chunks. When you use same variable names in more than on code chunks, evaluation of new chunks will effect the working of earlier chunks from where we have copy pasted. I faced this issue and it took me lots and lots of time to realize that, my variable values were being manipulated in many chunks so i was getting wrong values. Even if you copy paste the logic from other code chunks, Dont forget to rename the variables , so that each chunk has its own variables and chunks don't modify variables from other code chunks. 
Faced issue with twitteR package in R in authentication http 401 code in method,  ------------------------------------------------------------------- The below helped. consumer_key <- " YOUR CONSUMER KEY " consumer_secret<- " YOUR CONSUMER SECRET" setup_twitter_oauth(consumer_key, consumer_secret,  access_token=NULL , access_secret=NULL )
Feature of Scrolling in a page in RMarkdown Flexdashboard. ---------------------------------------------------------------------------------- I was using Flexdashboard with RMarkdown and faced an issue. When I was adding more rows, it used to squeeze the existing plots on the page and i was not getting the feature of scrolling automatically. I saw all the examples of Flexdashboard from the author, but every example had only 3-4 plots which fit in a single page. I search for some documentation but could not find one. Solution: We have to include a small key-value pair text, " vertical_layout: scroll" and it worked like magic and i had very nice scrolling feature on my page.
Accessing A variable from current Session in RMarkdown Code chunk . -------------------------------------------------------------------------------------------- When you run RStudio and click on Knitr Html to knit an R Markdown file it starts a new R session and you can not see the variables from other current running R Session. If you want to use Variables from the current session use rmarkdown:render("x.rmd") and it will run the markdown in the current session itself. But if the RMarkdown page contains shiny components as well rmarkdown:render given an error, "path for html_dependency not provided". To overcome that you have to use rmarkdown:run() function instead.
R. Biggest surprise. y <- 0 x <- function() {   y <- 5 } x() print(y) In the above code, Every object programmer or C programmer would expect, value of y to be printed as 5 after this code block gets executed. But it doesnt work this way in R. If you want to update global variable in R inside a function u have to use <<- instead of <- as assignment inside the function. so, x <- function() {   y <<- 5 } Would update the global variable y correctly :-). Was a big surprise for me.