R:调整HTML文件中的标题 [英] R: Adjusting Titles in HTML files

查看:68
本文介绍了R:调整HTML文件中的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R编程语言.我正在尝试将多个HTML文件保存在一起,如下所示:

I am working with the R programming language. I am trying to save multiple HTML files together like this:

library(plotly)
library(shiny)

#create widget_1

 widget_1 = plot_ly(iris, x = ~Sepal.Length, type = "histogram", nbinsx = 20)
  
    
#create_widget_2
  widget_2 = plot_ly(iris, x = ~Sepal.Width, type = "histogram", nbinsx = 20)

#create_widget_3
 widget_3 = plot_ly(iris, x = ~Petal.Length, type = "histogram", nbinsx = 20)

#create widget_4
 widget_4 = plot_ly(iris, x = ~Petal.Width, type = "histogram", nbinsx = 20)


doc <- htmltools::tagList(
  div(widget_1, style = "float:left;width:50%;"),
  div(widget_2,style = "float:left;width:50%;"),
  div(widget_3, style = "float:left;width:50%;"),
  div(widget_4, style = "float:left;width:50%;")
)

htmltools::save_html(html = doc, file = "C://Users//Me//Desktop//widgets.html")

上面的代码有效.现在,我尝试将标题(总体标题",标题1",标题2",标题3",标题4")标题化为最终文件,并在所有图形之间添加额外的空格,以便没有一个图形不重叠:

The above code works. Now, I am trying to titles ("overall title", "title 1", "title 2", "title 3", "title 4") to the final file and extra spaces between all graphs so that none of the graphs do not overlap:

我尝试查看taglist()函数的相应文档:

I tried looking at the respective documentation for the taglist() function:

tagList(tags$h1("Title"),
        tags$h2("Header text"),
        tags$p("Text here"))https://www.rdocumentation.org/packages/shiny/versions/0.9.1/topics/tagList))

但是我不确定如何将上述代码应用于html文件.

But I am not sure how I would apply the above code to the html file.

有人可以告诉我该怎么做吗?谢谢

Can someone please tell me how to do this? Thanks

推荐答案

library(htmltools)
library(plotly)

#create widget_1
widget_1 = plot_ly(iris, x = ~Sepal.Length, type = "histogram", nbinsx = 20)

#create_widget_2
widget_2 = plot_ly(iris, x = ~Sepal.Width, type = "histogram", nbinsx = 20)

#create_widget_3
widget_3 = plot_ly(iris, x = ~Petal.Length, type = "histogram", nbinsx = 20)

#create widget_4
widget_4 = plot_ly(iris, x = ~Petal.Width, type = "histogram", nbinsx = 20)


doc <- tagList(
  tags$h3(style = "text-align: center;", "Main title"),
  div(
    style = "display: flex; justify-content: space-between;",
    div(
      style = "display: flex; flex-direction: column; align-items: center; width: 45%",
      widget_1,
      tags$p("title 1")
    ),
    div(
      style = "display: flex; flex-direction: column; align-items: center; width: 45%",
      widget_2,
      tags$p("title 2")
    )
  ),
  div(style = "height: 50px;"),
  div(
    style = "display: flex; justify-content: space-between;",
    div(
      style = "display: flex; flex-direction: column; align-items: center; width: 45%",
      widget_3,
      tags$p("title 3")
    ),
    div(
      style = "display: flex; flex-direction: column; align-items: center; width: 45%",
      widget_4,
      tags$p("title 4")
    )
  )
)

browsable(doc)

这篇关于R:调整HTML文件中的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆