2013-09-30 50 views
2

我试图将RChart嵌入闪亮的应用程序中。我正在使用nPlot函数创建type=scatterChart NVD3样式图。在下面的NVD3网站例子,有两个功能件我感兴趣让我RCharts工作闪亮的应用:RCharts scatterChart增强功能

http://nvd3.org/ghpages/scatter.html

  1. 看来,一个“地毯”是沿x轴包括上面的例子的轴和y轴,稍微证明了x和y点在它们各自的支撑物上最频繁出现的位置。
  2. 此外,当点击图表并悬停在特定的点上时,会出现垂直和水平线,记下对应点的(x,y)位置。

有谁知道如何扩展我的代码以实现这两个功能。下面包含了闪亮的server.r和ui.r脚本。

## server.r 
library(rCharts) 
library(shiny) 

x <- rnorm(100) 
y <- rnorm(100) 
dat <- as.data.frame(cbind(x,y)) 

shinyServer(function(input, output) { 

output$myChart <- renderChart({ 

p1 <- nPlot(y ~ x, data = dat, type = "scatterChart") 

p1$addParams(dom = 'myChart') 

p1$params$height=400 
p1$params$width=650 

return(p1) 
}) 

}) 

## ui.R 
library(rCharts) 
library(shiny) 

shinyUI(pageWithSidebar(
headerPanel("rCharts: Interactive Charts from R using NVD3.js"), 

sidebarPanel(

wellPanel(
    helpText( "Look at the pretty graph" 
    ) 
    ), 

wellPanel(
    helpText( "Look at the pretty graph" 
    ) 
    ), 

wellPanel(
    helpText( "Look at the pretty graph" 
    ) 
    ) 

), 


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

) 
)) 

在此先感谢您提供的任何建议。

回答

6

这可以用下面的代码来实现:

p1$chart(
    showDistX = TRUE, 
    showDistY = TRUE 
) 

return(p1) 

而且,就像一个音符,而p1$params作品直接操纵,它可能是更安全的用这种方式来指定heightwidth

p1 <- nPlot(
    y ~ x, 
    data = dat, 
    type = "scatterChart", 
    height = 400, 
    width = 650 
) 
+0

完美工作。谢谢您的帮助!! – Chris