R shiny / rCharts / nvd3:覆盖固定的宽度和高度?

时间:2015-02-04 17:40:38

标签: r nvd3.js rcharts

我已经意识到,我为 nvd3 图表设置宽度和高度的所有尝试(包括添加我自己的css)都被某些内联css破坏了:

<style>
.rChart {width: 800px; height: 400px}
</style>

怎么办?我不知道它来自何处或如何阻止其输出。此外,我无法想到任何人为什么会首先为情节设置固定维度的任何理由......

更新:我不知道下面的每个评论都有一个renderChart2()。我尝试了如下:

  output$testChart <- renderChart2({

    n1 <- nPlot(xxx~yyy, data = xyz, type = 'discreteBarChart')
    n1$xAxis(axisLabel = "Heading")
    #bug with nv.d3.js - without width, the ylabel is off the chart area and invisible?
    n1$yAxis(axisLabel = "label", width = 40)
    n1$set(title = "Title")
    n1$chart(width=1600, height=800, tooltipContent = "#! function(key, x, y, e){ 
  return 'x: ' + e.point.x+ '<br/>  y: ' + y 
} !#")
    n1$addParams(dom = 'testChart') #need this line, else it doesn't get rendered in dom!
    return(n1)

  })

我在html输出中得到了这个(用firebug检查):

<div class="shiny-html-output rChart Nvd3 shiny-bound-output" id="testChart"><style>.rChart {width: 800px; height: 400px} </style>

<div class="rChart nvd3" id="testChart"></div>
<script type="text/javascript">
 $(document).ready(function(){
      drawtestChart()
    });
    function drawtestChart(){  
      var opts = {
 "dom": "testChart",
"width":    800,
"height":    400,
...(etc)...

ENV:

> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] markdown_0.7.4   knitr_1.8        rCharts_0.4.5    plyr_1.8.1       ggplot2_1.0.0   
[6] gplots_2.16.0    data.table_1.9.4 shiny_0.11      

是的,我有点超出我的深度......

1 个答案:

答案 0 :(得分:0)

尝试更改:

n1$chart(width=1600, height=800, tooltipContent = "#! function(key, x, y, e)

为:

n1$set(width=1600, height=800, tooltipContent = "#! function(key, x, y, e)