gpt4 book ai didi

rcharts nplot 仅在运行 Shiny 时显示在图的顶部

转载 作者:行者123 更新时间:2023-12-04 12:31:53 25 4
gpt4 key购买 nike

当我使用 Shiny 运行 rCharts 时,只有绘图的顶部显示在我的本地控制台中。我完全不知道这是为什么,我正在运行 rCharts 和 Shiny 的最新开发版本。任何帮助将不胜感激!

下面的两个文件应该可以完全重现问题。提前致谢,塞巴斯蒂安

## server.R
require(rCharts)
library(RCurl)
options(RCHART_WIDTH = 800)
shinyServer(function(input, output) {
output$myChart <- renderChart({
x <- getURL("https://raw.github.com/sebastianbarfort/vaa/master/vaa_.csv")
df___ <- read.csv(text = x)
p2 <- nPlot(Economy ~ Immigration, group = 'X.1', data = df___,
type = 'scatterChart')
p2$chart(color = c('red', 'blue', 'green',"yellow","yellow","yellow","yellow","yellow"))
p2$set(dom = "myChart")
return(p2)
})
})


##ui.R
require(rCharts)
shinyUI(pageWithSidebar(
headerPanel("xxx"),
sidebarPanel(
selectInput(inputId = "x",
label = "Choose X",
choices = c("CL", "Economy", "Education", "Envrionment", "EU",
"FP", "Health", "Immigration"),
selected = "Economy"),
selectInput(inputId = "y",
label = "Choose Y",
choices = c("CL", "Economy", "Education", "Envrionment", "EU",
"FP", "Health", "Immigration"),
selected = "Immigration")
),
mainPanel(
showOutput("myChart","Nvd3")
)
))

如果从 Github 加载 csv 失败(如果您加载 RCurl 则不会),这里是 Github 上数据的直接链接: https://github.com/sebastianbarfort/vaa/blob/master/vaa_.csv

最佳答案

这是一个快速修复。将您的 mainPanel 行修改为以下内容。图表 div 需要设置最小高度才能正确显示。我已经推送了一个修复程序来纠正这个问题,但它仍然有一个小错误。本周我将对 rCharts 进行更全面的修复,它应该会解决这个问题,并且不保证您添加 tags$style 行。

mainPanel(
div(class='wrapper',
tags$style(".Nvd3{ height: 400px;}"),
showOutput("myChart","Nvd3")
)
)

注意。在与 Shiny 一起使用时,最好使用非公式界面,因为 Shiny 输入被解释为字符串。 future 的版本可能会放宽此要求。因此,例如,初始化绘图的行将是

p2 <- nPlot(x = input$x, y = input$y, group = 'X.1', 
data = df___, type = 'scatterChart')

编辑。如果您安装了 rCharts 的 dev 版本(dev 分支),您可以像应用程序中那样添加基本控件,而不需要 Shiny。这是您将如何做的。此功能仍处于实验阶段,随着我继续简化代码库,API 会发生变化,因此请谨慎使用。

require(rCharts)
require(RCurl)
x <- getURL("https://raw.github.com/sebastianbarfort/vaa/master/vaa_.csv")
df___ <- read.csv(text = x)
p2 <- nPlot(Economy ~ Immigration,
group = 'X.1',
data = df___,
type = 'scatterChart'
)
p2$chart(color = c('red', 'blue', 'green',"yellow","yellow","yellow",
"yellow","yellow")
)
p2$addControls("x", value = "Immigration", values = names(df___)[-c(1:2)])
p2$addControls("y", value = "Economy", values = names(df___)[-c(1:2)])

关于rcharts nplot 仅在运行 Shiny 时显示在图的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17641443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com