R 亮日D3序列日暴图

R 亮日D3序列日暴图,r,d3.js,shiny,R,D3.js,Shiny,我正在做一个项目,需要制作一张太阳暴流序列图。我在D3.js上找到了一个示例,但我不知道如何将其放入闪亮的服务器功能中。有人知道怎么做吗 这是D3上太阳暴流图的链接:我应该给出一个免责声明,我不知道如何使用闪亮 我有一个目录,test,带有 server.R ui.R www/ sequences.js sequences.css index.html visit sequences.csv 首先,我使用此函数生成包含数据的visit sequences.csv文件 ## functio

我正在做一个项目,需要制作一张太阳暴流序列图。我在D3.js上找到了一个示例,但我不知道如何将其放入闪亮的服务器功能中。有人知道怎么做吗


这是D3上太阳暴流图的链接:

我应该给出一个免责声明,我不知道如何使用闪亮

我有一个目录,
test
,带有

  • server.R
  • ui.R
  • www/
    • sequences.js
    • sequences.css
    • index.html
    • visit sequences.csv
首先,我使用此函数生成包含数据的
visit sequences.csv
文件

## function to create the csv file
make_csv <- function(x, file = '~/desktop/test/www/visit-sequences.csv') {
  dd <- data.frame(ftable(x))
  dd <- within(dd, {
    visit <- apply(dd[, -ncol(dd)], 1, function(x)
      paste0(c(x, 'end'), collapse = '-'))
    count <- dd$Freq
  })

  write.table(dd[dd$count > 0, c('visit','count')], file = file, sep = ',',
              quote = FALSE, row.names = FALSE, col.names = FALSE)
}

set.seed(1)
dd <- sample(c('home','product','search','account','other'), 500,
             replace = TRUE, prob = c(.5,.3,.1,.05,.05))
dd <- as.data.frame(matrix(dd, ncol = 5))
make_csv(dd)
要在闪亮的应用程序中使用

server.R

## server.R
shinyServer(function(input, output) {
  ## nothing here
})
ui.R

## ui.R
shinyUI(pageWithSidebar(
  headerPanel(HTML('A sunburst chart in d3')),

  sidebarPanel(
    checkboxInput(
      inputId = 'dataSource',
      label = 'Select file.',
      value = FALSE
    ),

    conditionalPanel(
      condition = 'input.dataSource == false',
      textInput(inputId='url', label='File URL:', value='./visit-sequences.csv')
    ),

    conditionalPanel(
      condition = 'input.dataSource == true',
      fileInput(inputId = 'file', label='Data to plot:')
    )
  ),

  mainPanel(
    includeScript('./www/sequences.js'),
    includeCSS('./www/sequences.css'),
    includeHTML('./www/index.html')
  )
))
最后,跑

library('shiny')
runApp('~/desktop/test')
我明白了


但就像我说的,我真的不知道我在做什么。要更改标签、颜色和其他内容,您需要编辑js、html和css文件。

非常感谢,rawr。因为我不懂js、html和css,我只懂R,你的回答帮助我理解这三个部分是如何构成一个网页的。我想我需要先学习一下这些东西。由于我当前由shiny构建的应用程序还有其他内容,如果我只使用include函数调用css和js文件,那么这两个文件将应用于整个应用程序(其他页面)。无论如何,再次感谢您抽出时间。我很感激。
library('shiny')
runApp('~/desktop/test')