3

当我使用 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

4

1 回答 1

7

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

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

笔记。与 Shiny 一起使用时,最好使用非公式接口,因为 Shiny 输入被解释为字符串。未来的版本可能会放宽这一要求。因此,例如,初始化绘图的行将是

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

编辑。如果您dev安装了 rCharts 版本(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)])
于 2013-07-14T19:31:12.517 回答