按照RStudio在Shiny下的说明操作D3: https://rstudio.github.io/r2d3/articles/shiny.html#shiny-to-d3
我更新为Rstudio(1.2.1015),r2d3(0.2.2),闪亮(1.1.0)
当我尝试其示例代码时,我会在Rstudio Viewer中看到它,而不是单个的栏。
R代码示例为:
library(shiny)
library(r2d3)
ui <- fluidPage(
inputPanel(
sliderInput("bar_max", label = "Max:",
min = 10, max = 110, value = 10, step = 20)
),
d3Output("d3")
)
server <- function(input, output) {
output$d3 <- renderD3({
r2d3(
floor(runif(5, 5, input$bar_max)),
script = system.file("examples/baranims.js", package = "r2d3")
)
})
}
shinyApp(ui = ui, server = server)
system.file(“ examples / baranims.js”,package =“ r2d3”)返回的路径是/Library/Frameworks/R.framework/Versions/3.5/Resources/library/r2d3/examples/baranims.js
这是文件:
var barHeight = Math.floor(height / data.length);
var bars = r2d3.svg.selectAll('rect')
.data(r2d3.data);
bars.enter()
.append('rect')
.attr('width', function(d) { return d * width; })
.attr('height', barHeight)
.attr('y', function(d, i) { return i * barHeight; })
.attr('fill', 'steelblue');
bars.exit().remove();
bars.transition()
.duration(100)
.attr("width", function(d) { return d * width; });
答案 0 :(得分:0)
如果数据全部<1,似乎可以正常工作 不确定为什么使用此语句。
floor(runif(5,5,input $ bar_max))