如何在R中的同一HTML页面中导出两个HTML小部件?

时间:2017-09-13 20:07:52

标签: html r shiny shinydashboard

我们打算使用R创建一个包含两个(或更多)小部件的HTML页面。一个小部件包含时间轴,另一个小部件保存数据帧中的数据表。

我们可以创建两个单独的HTML页面,如下所示:

library(timevis)
library(htmlwidgets)

data <- data.frame(
  id      = 1:4,
  content = c("Item one", "Item two",
              "Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11",
              "2016-01-20", "2016-02-14 15:00:00"),
  end     = c(NA, NA, "2016-02-04", NA)
)

timevis(data)
htmlwidgets::saveWidget(timevis(data), "timeline.html", selfcontained = F)

另一个小部件是一个数据表,如下所示:

acs <- read.csv(url("http://stat511.cwick.co.nz/homeworks/acs_or.csv"))
acs_temp <- datatable(acs, options = list(pageLength = 10))
htmlwidgets::saveWidget(acs_temp, "page2.html", selfcontained = F)

这会保存两个单独的网页,用于保存时间轴可视化和HTML数据表。我们希望以这样的方式编写R脚本,即在同一HTML页面上插入表格和时间线可视化。我们怎么做到这一点?

1 个答案:

答案 0 :(得分:1)

使用R Markdown创建包含多个展览/小部件的html页面:

let urlOfSMARTCF = URL(string: "http://192.168.1.99/insertData.php")
let request = NSMutableURLRequest(url: urlOfSMARTCF! as URL)   request.httpMethod="POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")

for contact in contactsCaptuure
{
    let userMobileNumber = DBManager.shared.retriveRegisteredNumberOfMobile()    
    let postParameters = "\"usermobilenum\":\(String(describing: userMobileNumber!)),\"contactnum\":\(contact.phoneNumber!)";
    request.httpBody = postParameters.data(using: String.Encoding.utf8)
    let task = URLSession.shared.dataTask(with: request as URLRequest)
    {
        data, response, error in

        if error != nil
        {
            print("error is \(String(describing: error))")
            return;
        }
        do
        {
            print(response)
            let myJSON = try  JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
            if let parseJSON = myJSON
            {
                var msg : String!
                msg = parseJSON["message"] as! String?
                print(msg)

            }
        }
        catch
        {
            print(error.localizedDescription)
            print(error)
        }

    }
    print("Done")
    task.resume()
}