I've come to the realisation that all my attempts to set the width and height for my nvd3 chart (including adding my own css) are being sabotaged by some inline css:
<style>
.rChart {width: 800px; height: 400px}
</style>
What to do? I don't know where this is coming from or how to stop it from being output. Also, I can't think of any reasons why anybody would have set a fixed dimension for a plot in the first place...
UPDATE: I did not know there was a renderChart2() per comment below. I tried it as follows:
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)
})
And I got this in the html output (checked with 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
And yes, I'm a bit out of my depth..
800px
and400px
match the height and width you set for your chart? – timelyportfolio