2013-09-30 46 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