Shiny and rCharts/Polycharts with both X- and Y-axis choice input

261 views Asked by At

I have a problem where I import a large data set, then generate some selection input from that data set, and then want to be able to have a plot where I can freely choose my x- and y-axis from the data set.

I keep crashing the browser, with my current code - I believe it has something todo with rCharts trying to generate the polychart, with variables not yet available - my custom input has to load first. I've tried both using reactive parts and isolating the output, and other stuff - either I am not doing it correctly, or its not the right way - either way it isn't working.

I am rather new to shiny, R and especially rCharts, but I got my graphs working with only one input - Problem arises when trying to make the multiple selectable.

I have the three following UIs that gives input to the renderCharts, which I show below:

    output$TestSelection <- renderUI({
          selectInput("TestSel", "Test Variable", ls(df, pattern = ".*?_meas|.*?_calc"))
    })
    output$customx <- renderUI({
          selectInput("xcustom", "Custom Graph - X", ls(df), selected = input$TestSel) 
    }) 
    output$customy <- renderUI({
         selectInput("ycustom", "Custom Graph - Y", ls(df), selected = input$TestSel) 
    }) 

And the renderChart2 code:

   output$customplot <- renderChart2({
      if(is.null(input$xcustom)|is.null(input$ycustom))
        return(rCharts$new())

      #Removing all unneccessary data from dataframe,
      dataPlot <- df[,c("DUT", input$ycustom, input$xcustom)]

      custom_chart <- rPlot(x = input$xcustom,y = input$ycustom,
                            data = dataPlot, 
                            type = "point", 
                            tooltip = "#!function(item){return item.DUT}!#", 
                            sample = FALSE)

      #Adjusting width to fit the current screen
      custom_chart$set(width = session$clientData$output_plot2_width , title = paste(input$ycustom, " vs. ", input$ycustom, sep =""))

      #Setting the correct axis
      axisincrease = abs((max(dataPlot[,input$xcustom])-min(dataPlot[,input$xcustom]))*0.05)

      custom_chart$guides(
       x = list(
          min = pretty(dataPlot[,input$xcustom])[1]-axisincrease,
          max = tail(pretty(dataPlot[,input$xcustom]),1)+axisincrease,
          numticks = length(dataPlot[,input$xcustom])
        ),
       y = list(
          min = pretty( dataPlot[, input$ycustom] ) [1],
          max = tail( pretty( dataPlot[, input$ycustom] ), 1 )
       )
       )
       return(custom_chart)})
0

There are 0 answers