rCharts rnvd3 not rendering correctly in shinydashboard - r

I am trying to add a rChart and nvd3 plot a shiny dashboard.
However only the top part of the graph shows. and does not even fill the panel which is created.
my code ui code is
showOutput("myPlot")
I have also tried to alter it using the following
div(class='wrapper', tags$style(".Nvd3{ height: 700px;}"),
showOutput("myPlot"))
but all this seems to do is create a box the same colour as the shiny dashboard side bar.
My server code #
output$myPlot<- renderChart({
plotdataukv <- nPlot(verifiedUsers ~ date, group="group", data = myData, type = 'lineChart', dom = 'myPlot')
plotdataukv$xAxis(axisLabel = 'Time (Days)', tickFormat="#!function(d) {return d3.time.format('%d/%m/%Y')(new Date( d * 86400000 ));}!#", rotateLabels=-90 )
plotdataukv$yAxis(axisLabel = 'My Metric')
plotdataukv$chart(color = c('blue', 'red'))
return(plotdataukv)
})

Code:
output$myPlot<- renderChart({
plotdataukv <- nPlot(verifiedUsers ~ date, group="group", data = myData, type = 'lineChart', dom = 'myPlot')
plotdataukv$xAxis(axisLabel = 'Time (Days)', tickFormat="#!function(d) {return d3.time.format('%d/%m/%Y')(new Date( d * 86400000 ));}!#", rotateLabels=-90 )
plotdataukv$yAxis(axisLabel = 'My Metric')
plotdataukv$chart(color= c('blue', 'red'))
plotdataukv$set(dom = 'myPlot')
return(plotdataukv)
})
showOutput("myPlot", "nvd3")
I hope the above code is working properly..

Related

I am trying to figure out how to create custom tooltips that show up when hovering over an axis label in highcharter in R

This jsfiddle example shows what I am trying to do in highcharter in r:
http://jsfiddle.net/key2xanadu/zfsfz0c9/
Here is a very simple example that I am trying to get to work in R:
x <- c(0,1)
y <- c(29.9, 71.5)
data <- cbind(x,y)
data <- as.data.frame(data)
data %>%
hchart('line', hcaes(x = x, y = y)) %>%
hc_xAxis(
labels = list(
enabled = TRUE,
categories = c('one', 'two'),
formatter = JS("function(){
$('document').ready(function () {
$('#text_title').tooltip({placement: 'bottom', title:'HELLO TITLE!'});
$('#label_one').tooltip({placement: 'bottom', title:'HELLO ONE!'});
$('#label_two').tooltip({placement: 'bottom', title:'HELLO TWO!'});
});
}"
),
useHTML = TRUE
)
)
I am missing something though because it is not showing the xaxis labels or a tooltip that I want to show up when I hover. Any insight would be so much appreciated!

R Shiny HTMLWidget for interactive 3D-histograms

I would like to include a 3D dynamic (i.e. one can change its perspective just by moving the plot) histogram widget in a R Shiny application.
Unfortunately I didn't find any until now.
So far the results of my searches: with threejs (e.g. here on CRAN and there on GitHub) one can use many different representations (scatterplots, surfaces, etc.) but no 3D histogram. plot3D and plot3Drgl don't have any R Shiny counterpart.
Unless something already exists my intention is to create an HTMLWidget from one of the sub-libraries of vis.js, namely graph3d.
What are your views on this issue?
Best regards,
Olivier
It's possible with plot3Drgl. Here is an example.
library(plot3Drgl)
library(shiny)
options(rgl.useNULL = TRUE)
ui <- fluidPage(
rglwidgetOutput("myWebGL")
)
server <- function(input, output) {
save <- options(rgl.inShiny = TRUE)
on.exit(options(save))
output$myWebGL <- renderRglwidget({
try(rgl.close())
V <- volcano[seq(1, nrow(volcano), by = 5),
seq(1, ncol(volcano), by = 5)] # lower resolution
hist3Drgl(z = V, col = "grey", border = "black", lighting = TRUE)
rglwidget()
})
}
shinyApp(ui, server)
My package graph3d is on CRAN now.
library(graph3d)
dat <- data.frame(x = c(1,1,2,2), y = c(1,2,1,2), z = c(1,2,3,4))
graph3d(dat, type = "bar", zMin = 0, tooltip = TRUE)
You can customize the tooltips:
graph3d(dat, type = "bar", zMin = 0,
tooltip = JS(c("function(xyz){",
" var x = 'X: ' + xyz.x.toFixed(2);",
" var y = 'Y: ' + xyz.y.toFixed(2);",
" var z = 'Z: ' + xyz.z.toFixed(2);",
" return x + '<br/>' + y + '<br/>' + z;",
"}"))
)
I realize I have to add an option to control the size of the axes labels...
Many thanks, DSGym. I didn't know this library.
In my initial message (now amended) I actually forgot to mention the dynamic feature, i.e. the ability to change the perspective of the plot just by moving it with the mouse, like with vis.js-graph3d.
It seems plots from highcharter cannot do that, or am I mistaken?
[EDIT]: I just checked with Shiny: it is static.

Remove legend from rChart

I am using rCharts library in a Shiny application and want to remove the right side legend.
The tips I found did not work in this case...
for example: p1$chart(showLegend = FALSE)
My code is similar to this one:
library(rCharts)
mydata<-data.frame(weekday=c("friday","monday","thursday","tuesday","saturday","sunday","wednesday"),value=rnorm(7,10,2))
p1<-rPlot(value ~ weekday, color = 'weekday', data = mydata, type = 'bar')
p1$guides(
color = list(
numticks = length(unique(mydata$weekday))
),
x = list(title="",
ticks = c('sunday', 'monday', 'tuesday','wednesday','thursday','friday','saturday'),
labels ="",
levels = c('sunday', 'monday', 'tuesday','wednesday','thursday','friday','saturday')
),
y = list(title=""
)
)
p1$chart(showLegend = FALSE)
p1
I solved the problem using the following code line:
p1$set(legendPosition = "none")

Observation data is not shown in the shiny application

I'm building a simple application in shiny to look at data divided to quadrants.
this is the server file:
shinyServer(function(input, output){
output$chart1 = renderChart({
library(rCharts)
data = data.frame(z = c("a","b","c","d","e","f","g","h","i","j"),y = sample(100,10),x = sample(100,10))
d1 = dPlot(
y ~ x,
groups = c("z"),
data =data,
type = "bubble"
)
d1$xAxis(type="addMeasureAxis",overrideMin = 0, overrideMax = 100)
d1$yAxis(type="addMeasureAxis",overrideMin = 0, overrideMax = 100)
medY = median(data$y)
medX = median(data$x)
d1$setTemplate(
afterScript = sprintf(
paste(
'
<script>
var line = d3.svg.line()
.x(function(d) { return myChart.axes[0]._draw.scale()(d.x); })
.y(function(d) { return myChart.axes[1]._draw.scale()(d.y); });
d3.select("#%s svg g")
.append("path")
.datum([{x:',medX,',y:0},{x:',medX,',y:100}])
.attr("d",line)
.style("stroke","red")
.style("stroke-width",1)
</script>
'
,sep = "")
,d1$params$dom
))
d1$layer(
y ~ x
,groups = c("x","y")
,data = data.frame(x = c(0,100), y = rep(medX,2))
,type="line"
,color='red'
)
d1$set(dom = 'chart1')
return(d1)
})
})
and here is the ui:
shinyUI(pageWithSidebar(
headerPanel("Test"),
sidebarPanel(),
mainPanel(showOutput("chart1", lib = "dimple"))
))
I get a chart but when I hover above the data points in the chart there is no description inside the boxes.
When I run the same code without the shiny application and look at the output at the viewer on RStudio i see the description.
I also added a vertical line which is not seen in the shiny application.
Anyone knows how to overcome this problem?
Thanks.

nPLot x-axis Date variable and default stacked Bar plot in rCharts

I am using nPlot, my X-axis is Date variable, I want this to just Date as in my data 'YYYY-MM-DD', tilted vertically (90 degrees). I want nPlot show the chart stacked by default. Please help me out.
output$testChart = renderChart({
testChart = nPlot(Count~Date, data = df, group = 'Category',
type = 'multiBarChart')
testChart$chart(reduceXTicks = F)
testChart$xAxis(staggerLabels = T)
testChart$chart(stacked = T)
testChart$xAxis(tickFormat = "#! d3.time.format('%Y-%m-%d') !#")
return(testChart)
})
and in server.R
output$mytabs = renderUI({
tabs = tabsetPanel(
tabPanel('Tab1', h5("Tab1"),
fluidRow(showOutput("testChart"))
)
)
mainPanel(tabs)
})
in ui.R
uiOutput('mytabs')
Suppose that you stored your plot in the object n1. Here is how you can customize it do what you seek.
n1$chart(stacked = TRUE)
n1$xAxis(
tickFormat = "#! d3.time.format('%Y-%m-%d') !#",
rotateLabels = 90
)
n1
I have no way to verify that this works. So I would suggest that you post your data and the code that you used to generate this plot. Doing so, even this works for you, would be useful as it would help others who come across this question.

Resources