mmann1123
mmann1123

Reputation: 5295

R: Store mutliline html text and pass as an object

I am trying to integrate googleVis and KML. I need to be able to pass on object storing multiple lines of html code to the popup window in my KML object. However I cannot figure out how to store a multiline text object in R. Because i need to paste HTML i cannot have line breaks like '\n' etc.

Here is a non-working example:

install.packages('googleVis')
library(googleVis)
chart =  gvisCandlestickChart(OpenClose, xvar="Weekday", low="Low",
                                    open="Open", close="Close",
                                    high="High",
                                    options=list(legend='none'))

I need to store an object that is identical to

print(chart)
"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CandlestickChartID27d81b892d9b</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<style type="text/css">
body {
...."

Essentially I need to pass an object holding valid html code that can be used for my KML popup window.

I have tried a variety of methods. paste adds '\n', cat can't be stored as multiline. The closest I have come is to do the following

  description <-   capture.output(cat(unlist(chart$html)))

which gives:

 head(description)
[1] "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""              
[2] "  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"                
[3] "<html xmlns=\"http://www.w3.org/1999/xhtml\">"                           
[4] "<head>"                                                                  
[5] "<title>CandlestickChartID27d81b892d9b</title>"                           
[6] "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />"

Any suggestions??? Any way to store an HTML object?

Upvotes: 1

Views: 118

Answers (2)

mmann1123
mmann1123

Reputation: 5295

Seems like you can use it as html if you change the carriage return from '\n' to '\r'

  description <-  paste( capture.output(cat(unlist(chart$html))),collapse='\r')

Description can now be passed as an object containing html code! yeah.

Upvotes: 0

Manjunath Siddappa
Manjunath Siddappa

Reputation: 2157

i am not able to understand what you are trying to achieve. it will be helpful if you add your code in jsfiddle, so that experts can understand the problem and answer in less time

i suggest try to add <br> tag inside the text,so it will become multi line and you can break wherever you required.

thanks

Upvotes: 1

Related Questions