如何优雅吃瓜 -- 用R Shiny App制作王力宏事件可交互时间线



  • R里有一个叫做timevis的包,和Shiny结合使用可以进行交互时间线图的制作。

    做出的时间线图支持滚轮缩放和拖曳等基本的交互功能。示例图如下:

    22a5bc96-bce3-4429-86a5-ccae8d2e8a20-image.png

    可以看到事件的高潮发生在18日,双方的斗争相当激烈,直到20日,随着王力宏的道歉逐渐停歇。

    library(shiny)
    library(timevis)
    
    data <- data.frame(
      id      = 1:8,
      content = c("宣布离婚", "李靚蕾发布小作文",
                  "英菲尼迪宣布终止和王力宏的合作", "Yumi 社交平台发布报警信息", "李靚蕾反击","王力宏爸爸写亲笔信","王力宏反击","王力宏道歉"),
      start   = c("2021-12-15", "2021-12-17",
                  "2021-12-18", "2021-12-18", "2021-12-18", "2021-12-18", "2021-12-19", "2021-12-20"),
      end     = c(NA, NA,NA, NA,NA, NA,NA, NA)
    )
    
    ui <- fluidPage(
      timevisOutput("timeline")
    )
    
    server <- function(input, output, session) {
      output$timeline <- renderTimevis({
        timevis(data)
      })
    }
    
    shinyApp(ui = ui, server = server)
    

    参考文献:
    https://www.womensweekly.com.sg/gallery/entertainment/wang-leehom-and-li-jinglei-saga-timeline/?utm_source=facebook&utm_medium=social-organic&utm_keyword=dlvr.it



  • 如果想要更加Fancy一点,可以试试把这些Message分成两组,jinglei组和Lihong组,并且用Editable的格式,让我们可以编辑每一条时间线
    2c9340ba-3721-4340-8f42-9b4a5695bbcd-image.png

    library(shiny)
    library(timevis)
    
    data <- data.frame(
      id      = 1:8,
      group = c("WLH","LJL","LJL","WLH","LJL","WLH","WLH","WLH"),
      content = c("宣布离婚", "李靚蕾发布小作文",
                  "英菲尼迪宣布终止和王力宏的合作", "Yumi 社交平台发布报警信息", "李靚蕾反击","王力宏爸爸写亲笔信","王力宏反击","王力宏道歉"),
      start   = c("2021-12-15", "2021-12-17",
                  "2021-12-18", "2021-12-18", "2021-12-18", "2021-12-18", "2021-12-19", "2021-12-20"),
      end     = c(NA, NA,NA, NA,NA, NA,NA, NA)
    )
    group<- data.frame(
      id      =c("WLH","LJL"),
      content = c("王力宏方","李靚蕾方")
    )
    
    
    
    ui <- fluidPage(
      timevisOutput("timeline")
    )
    
    server <- function(input, output, session) {
      output$timeline <- renderTimevis({
        timevis(data,groups=group, options = list(editable = TRUE))
      })
    }
    
    shinyApp(ui = ui, server = server)
    
    


  • 這是我看過最有趣的應用.



  • @ekuo 哈哈,谢谢


登录后回复