0

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.

user2721827
  • 183
  • 1
  • 2
  • 7
  • Do you have D3 loaded into the server or wherever you are hosting the Shiny app? D3.js needs to be called / downloaded in order to use its functions. Have you done that? That may be why it is not showing up in the browser. – squishy Nov 18 '14 at 16:26
  • The shiny app is run from RStudio, so it hosted on my local machine, am i right? in that case d3.js should be there. – user2721827 Nov 19 '14 at 08:10
  • Well there are multiple ways to run Shiny apps. You can host them through your own server (if you have one), through the RStudio servers, etc. I think this is a good reference for you: http://stackoverflow.com/questions/26650561/binding-javascript-d3-js-to-shiny. From this question, some recommend Plotty for R users (it uses D3 in the background). When you run the Shiny app in your browser with Developer Tools on ("command + option + i" if on Chrome and Mac). What does it say? Any errors? Should show an error if it is not reading D3. – squishy Nov 19 '14 at 21:17

0 Answers0