rmarkdown生成html的宽度,shiny学习笔记3--利用rmarkdown生成html报告

第一个博文讲了如何构建shiny app, 如何上传数据.

第二个博文讲了如何利用shiny app, 下载数据.

这里我们利用下载报表, 使用的是rmarkdown格式. 功能很强大.

流程

1, 生成数据代码:

ID = 1:20

y = rnorm(20)

dat = data.frame(ID,y)

2, 生成一个rmarkdown文件, head, summary, plot, 以及内容.

3, 下载报表

shiny 代码

app.R

library(shiny)

library(data.table)

library(shinydashboard)

ui = dashboardPage(

dashboardHeader(title = "如何上传数据"),

dashboardSidebar(

menuItem("生成数据",tabName = "a")

),

dashboardBody(

tabItems(

tabItem(tabName = "a",

tableOutput("head"),

downloadButton("down1","下载rmarkdown的html报表"))

)

)

)

server

d1

ID = 1:20

y = rnorm(20)

dat = data.frame(ID,y)

})

output$head

dat= d1()

head(dat)

})

output$down1

filename = function() {

paste('Data-summary', Sys.time(), sep = '.', 'html')

},

content = function(file) {

dat = d1()

src

owd

on.exit(setwd(owd))

file.copy(src, 'rmarkdown1.Rmd', overwrite = TRUE)

library(rmarkdown)

out

file.rename(out, file)

})

}

shinyApp(ui = ui, server = server)

rmarkdown1.Rmd

将其放在app.R相同的文件夹中.

# First title

> 引用

## 二级标题

```{r}

1+12

```

## head

```{r}

head(dat)

```

## summary

```{r}

summary(dat)

```

## plot

```{r}

plot(dat)

```

shiny运行界面

eedceed8530db80b37715fda1bf6deb9.png

下载的html界面:

79fe868c1d4001c04160dd4938c9d54f.png

可以看到, 虽然不支持中文, 但是该有的markdown还是都有的. 可以用于自动化报表的生成.

其它相关

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值