xtable links
3
0
Entering edit mode
Tim Smith ★ 1.1k
@tim-smith-1532
Last seen 9.6 years ago
Hi, I was trying to get hyperlinks using xtable, but couldn't get the hyperlinks to function properly. For example, if I use ## Try to link NY times website to every figure in column 4 mat <- matrix(1:43,6,5) mat[,5] <- "http://nytimes.com" for(i in 1:nrow(mat)){ strr <- paste('', mat[i,4], '', sep='') mat[i,4] <- strr } mat2 <- mat[,1:4] caption = 'test' mx <- xtable(mat2,caption=caption) tt = print(mx, type="html",include.rownames=F) tt1 <- gsub('lt /a','lt/a',tt,fixed=T) tt2 <- gsub('lt a','lta',tt1,fixed=T) write.table(tt2,'test.html',quote=F) However, if I open 'test.html' in IE, the hyperlinks don't seem to work. What am I doing wrong? thanks. [[alternative HTML version deleted]]
• 1.5k views
ADD COMMENT
0
Entering edit mode
Tim Smith ★ 1.1k
@tim-smith-1532
Last seen 9.6 years ago
Thanks Sean. The table itself seems to come out fine in the browser - only the hyperlinks don't work! Everything else appears to be formatted. ________________________________ From: Sean Davis <sdavis2@mail.nih.gov> Cc: bioc <bioconductor@stat.math.ethz.ch> Sent: Friday, December 5, 2008 4:17:46 PM Subject: Re: [BioC] xtable links > Hi, > > I was trying to get hyperlinks using xtable, but couldn't get the hyperlinks to function properly. For example, if I use > > ## Try to link NY times website to every figure in column 4 > mat <- matrix(1:43,6,5) > mat[,5] <- "http://nytimes.com" > > for(i in 1:nrow(mat)){ > strr <- paste('', mat[i,4], '', sep='') > mat[i,4] <- strr > } > mat2 <- mat[,1:4] > > caption = 'test' > mx <- xtable(mat2,caption=caption) > tt = print(mx, type="html",include.rownames=F) > tt1 <- gsub('lt /a','lt/a',tt,fixed=T) > tt2 <- gsub('lt a','lta',tt1,fixed=T) > > write.table(tt2,'test.html',quote=F) xtable converts the table to HTML. You won't want to use write.table on that. Use something like writeLines(). Also, the HTML output by xtable is only the "table" part; you will need to put appropriate HTML header, body, etc. around the table in order for it to work in a browser. > However, if I open 'test.html' in IE, the hyperlinks don't seem to work. What am I doing wrong? > > thanks. > > > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT
0
Entering edit mode
Hi Tim, Alternatively, you may want to use the CRAN package hwriter: library(hwriter) mat=matrix(1:24,6,4) colnames(mat)=1:4 hmat=hwrite(mat, col.link=list('4'=rep('http://nytimes.com', 6)), col.names=T, row.style='text-align:center ; font-weight:bold') hcap=hwrite('test', center=T) hwrite(c(hmat,hcap), 'test.html', dim=c(2,1), border=0) For more details and CSS styling options, please check: http://www.ebi.ac.uk/~gpau/hwriter/ Best regards, Greg -- Gregoire Pau EMBL/EBI Cambridge, UK http://www.ebi.ac.uk/~gpau Tim Smith wrote: > Thanks Sean. > > The table itself seems to come out fine in the browser - only the hyperlinks don't work! Everything else appears to be formatted. > > > > > > > > ________________________________ > From: Sean Davis <sdavis2 at="" mail.nih.gov=""> > > Cc: bioc <bioconductor at="" stat.math.ethz.ch=""> > Sent: Friday, December 5, 2008 4:17:46 PM > Subject: Re: [BioC] xtable links > > >> Hi, >> >> I was trying to get hyperlinks using xtable, but couldn't get the hyperlinks to function properly. For example, if I use >> >> ## Try to link NY times website to every figure in column 4 >> mat <- matrix(1:43,6,5) >> mat[,5] <- "http://nytimes.com" >> >> for(i in 1:nrow(mat)){ >> strr <- paste('', mat[i,4], '', sep='') >> mat[i,4] <- strr >> } >> mat2 <- mat[,1:4] >> >> caption = 'test' >> mx <- xtable(mat2,caption=caption) >> tt = print(mx, type="html",include.rownames=F) >> tt1 <- gsub('lt /a','lt/a',tt,fixed=T) >> tt2 <- gsub('lt a','lta',tt1,fixed=T) >> >> write.table(tt2,'test.html',quote=F) > > xtable converts the table to HTML. You won't want to use write.table > on that. Use something like writeLines(). Also, the HTML output by > xtable is only the "table" part; you will need to put appropriate HTML > header, body, etc. around the table in order for it to work in a > browser. > >> However, if I open 'test.html' in IE, the hyperlinks don't seem to work. What am I doing wrong? >> >> thanks. >> >> >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >> > > > > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY
0
Entering edit mode
@sean-davis-490
Last seen 3 months ago
United States
On Fri, Dec 5, 2008 at 4:08 PM, Tim Smith <tim_smith_666 at="" yahoo.com=""> wrote: > Hi, > > I was trying to get hyperlinks using xtable, but couldn't get the hyperlinks to function properly. For example, if I use > > ## Try to link NY times website to every figure in column 4 > mat <- matrix(1:43,6,5) > mat[,5] <- "http://nytimes.com" > > for(i in 1:nrow(mat)){ > strr <- paste('', mat[i,4], '', sep='') > mat[i,4] <- strr > } > mat2 <- mat[,1:4] > > caption = 'test' > mx <- xtable(mat2,caption=caption) > tt = print(mx, type="html",include.rownames=F) > tt1 <- gsub('lt /a','lt/a',tt,fixed=T) > tt2 <- gsub('lt a','lta',tt1,fixed=T) > > write.table(tt2,'test.html',quote=F) xtable converts the table to HTML. You won't want to use write.table on that. Use something like writeLines(). Also, the HTML output by xtable is only the "table" part; you will need to put appropriate HTML header, body, etc. around the table in order for it to work in a browser. > However, if I open 'test.html' in IE, the hyperlinks don't seem to work. What am I doing wrong? > > thanks. > > > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 1 hour ago
United States
Hi Tim, Tim Smith wrote: > Hi, > > I was trying to get hyperlinks using xtable, but couldn't get the hyperlinks to function properly. For example, if I use > > ## Try to link NY times website to every figure in column 4 > mat <- matrix(1:43,6,5) > mat[,5] <- "http://nytimes.com" > > for(i in 1:nrow(mat)){ > strr <- paste('', mat[i,4], '', sep='') > mat[i,4] <- strr > } > mat2 <- mat[,1:4] > > caption = 'test' > mx <- xtable(mat2,caption=caption) > tt = print(mx, type="html",include.rownames=F) > tt1 <- gsub('lt /a','lt/a',tt,fixed=T) > tt2 <- gsub('lt a','lta',tt1,fixed=T) Your html is malformed: > mat2 [,1] [,2] [,3] [,4] [1,] "1" "7" "13" "19" [2,] "2" "8" "14" "20" [3,] "3" "9" "15" "21" [4,] "4" "10" "16" "22" [5,] "5" "11" "17" "23" [6,] "6" "12" "18" "24" So you need to fix that first (e.g., "19") In addition, you don't use write.table() with xtable. You want to use print(mx, file="test.html", type="html") Also you might want to add caption.placement="top" if you want the caption to be at the top of the page. Best, Jim > > write.table(tt2,'test.html',quote=F) > > However, if I open 'test.html' in IE, the hyperlinks don't seem to work. What am I doing wrong? > > thanks. > > > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- James W. MacDonald, M.S. Biostatistician Hildebrandt Lab 8220D MSRB III 1150 W. Medical Center Drive Ann Arbor MI 48109-0646 734-936-8662
ADD COMMENT

Login before adding your answer.

Traffic: 902 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6