【问题标题】:R shiny / rCharts / nvd3 : override fixed width and height?R shiny / rCharts / nvd3:覆盖固定宽度和高度?
【发布时间】:2015-02-06 01:12:12
【问题描述】:

我意识到我为 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)...

环境:

> 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      

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

【问题讨论】:

  • 您是否将上面的原始 css 直接添加到闪亮的应用程序中?
  • 不...这个原始 css 是由 r shiny 和或 r 图表的某种组合生成的。它不是我的,我不想要它,我不知道如何摆脱它或覆盖它,lol
  • 您应该在此论坛上发布解决问题的尝试。这里有很多高手一直致力于将主题整合到您的标题中。除此之外,在我看来,你有点超出你的深度,这很好。您是否正在寻找开发闪亮的应用程序?说明你的目标很重要,但一点也不明确。
  • 我觉得现在好多了。看看这些行github.com/ramnathv/rCharts/blob/master/R/renderChart.R#L51-L60。你用的是最新版本吗?如果是这样,800px 和 400px 是否与您为图表设置的高度和宽度相匹配?
  • 另外,这可能会有所帮助stackoverflow.com/questions/28134392/…

标签: r nvd3.js rcharts


【解决方案1】:

尝试改变:

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

到:

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

【讨论】:

    猜你喜欢
    • 2013-01-06
    • 1970-01-01
    • 2019-11-16
    • 2018-03-20
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    相关资源
    最近更新 更多