我正在使用闪亮的自定义模板,我希望它使用模板的美学来显示数据框。出于这个原因,我需要解析这个数据框:
data_frame(name=letters[1:5], value=1:5)
Source: local data frame [5 x 2]
name value
(chr) (int)
1 a 1
2 b 2
3 c 3
4 d 4
5 e 5
进入这个
<tr>
<th scope="row">1</th>
<td>a</td>
<td>1</td>
</tr>
<tr>
<th scope="row">2</th>
<td>b</td>
<td>2</td>
</tr>
<tr>
<th scope="row">3</th>
<td>c</td>
<td>3</td>
</tr>
然后使用index.html
将其放入{{tableName}}
文件中。哪种方式最合适?
答案 0 :(得分:2)
print.xtable
功能有&#39;类型&#39;允许你构造html表的参数
require(xtable)
require(dplyr)
obj <- data_frame(name=letters[1:5], value=1:5)
print( xtable(obj), type="html")
<!-- html table generated in R 3.2.3 by xtable 1.8-2 package -->
<!-- Sat Mar 19 16:57:05 2016 -->
<table border=1>
<tr> <th> </th> <th> name </th> <th> value </th> </tr>
<tr> <td align="right"> 1 </td> <td> a </td> <td align="right"> 1 </td> </tr>
<tr> <td align="right"> 2 </td> <td> b </td> <td align="right"> 2 </td> </tr>
<tr> <td align="right"> 3 </td> <td> c </td> <td align="right"> 3 </td> </tr>
<tr> <td align="right"> 4 </td> <td> d </td> <td align="right"> 4 </td> </tr>
<tr> <td align="right"> 5 </td> <td> e </td> <td align="right"> 5 </td> </tr>
</table>