timelyportfolio / parcoords

R htmlwidget for parallel-coordinates chart
https://timelyportfolio.github.io/parcoords/
Other
77 stars 21 forks source link

shiny rendering failing #3

Closed markriseley closed 9 years ago

markriseley commented 9 years ago

parcoords doesn't render in Shiny (but it works beautifully in RStudio viewer / localhost browser).

In javascript console log I get error "uncaught TypeError: string is not a function", the shiny bindings / parcoords.js:67 line is the offender. I have made a pull request for the fix.

        d3.keys(d3.nest().key(function(d){return d[x.options.color.colorBy]}).map(x.data)).map(function(c){
      colors[c] = colorScale(c);

Change '=colorScale(c)' to '=colorScale[c]' and it works.

I think this is fantastic btw, keep the widgets coming... I really love parcoords!

Minimum reproducible example below (the parcoords piece works on its own, just not wrapped in shiny until you fix the bracket issue):

# app.R
# minimal shiny app with parcoords
library(shiny)
library(parcoords)

data(mtcars)

ui <- basicPage(
        absolutePanel(width=1000, "Parcoords in shiny", parcoordsOutput("par") )
    )

server <- function(input, output) {
   # simple parcoords  
    output$par <- renderParcoords({
        parcoords(mtcars, rownames = T
                  , brushMode = "1d-axes"
                  , reorderable = T
                  , queue = F
                  , color = list(
                      colorBy = "cyl"
                      , colorScale = htmlwidgets::JS("d3.scale.category20()"))
                  )
    })
}

shinyApp(ui, server)

And session info after running the above code: NB I'm Win 8.1 64 bit.

Session info --------------------------------------------------------------------------------------------------------- setting value
version R version 3.1.2 (2014-10-31) system x86_64, mingw32
ui RStudio (0.99.235)
language (EN)
collate English_United Kingdom.1252 tz Europe/London

Packages ------------------------------------------------------------------------------------------------------------- package * version date source
devtools * 1.7.0 2015-01-17 CRAN (R 3.1.2)
digest * 0.6.8 2014-12-31 CRAN (R 3.1.2)
htmltools * 0.2.6 2014-09-08 CRAN (R 3.1.2)
htmlwidgets * 0.3.2 2014-12-09 CRAN (R 3.1.2)
httpuv * 1.3.2 2014-10-23 CRAN (R 3.1.2)
jsonlite * 0.9.14 2014-12-01 CRAN (R 3.1.2)
mime * 0.2 2014-09-26 CRAN (R 3.1.2)
parcoords 0.1 2015-02-10 Github (timelyportfolio/parcoords@6817d24) R6 * 2.0.1 2014-10-29 CRAN (R 3.1.2)
Rcpp * 0.11.4 2015-01-24 CRAN (R 3.1.2)
RJSONIO * 1.3-0 2014-07-28 CRAN (R 3.1.2)
rstudioapi * 0.2 2014-12-31 CRAN (R 3.1.2)
shiny 0.11.0.9001 2015-02-04 Github (rstudio/shiny@424696c)
xtable * 1.7-4 2014-09-12 CRAN (R 3.1.2)
yaml * 2.1.13 2014-06-12 CRAN (R 3.1.2)

timelyportfolio commented 9 years ago

Very odd, since I just verified that the code is correct. I wonder if it is a browser issue. What browser are you using? In the console, could you break at the line in question and copy/paste c and colorScale here?

Also very happy you are using this. Thanks so much for the feedback and reproducible example.

markriseley commented 9 years ago

If I use your version it works fine in Rstudio viewer and in shiny if there's only a fixed colour. Colorscales causes a fail in shiny. If I use my edit, it renders in shiny for both but colorscales won't change colours from the default.

Your version renders ok in shiny for me but only if you don't have colorscales.

Either way colorscales is not playing nice in shiny wrapped objects.

On 18 February 2015 at 17:04, timelyportfolio notifications@github.com wrote:

Very odd, since I just verified that the code is correct. I wonder if it is a browser issue. What browser are you using?

— Reply to this email directly or view it on GitHub https://github.com/timelyportfolio/parcoords/issues/3#issuecomment-74902666 .

timelyportfolio commented 9 years ago

When I run your example, it works perfectly with shiny in both the viewer, chrome, and Firefox with no changes to the code. Also, looking at the code it applies correctly the function to the value. Still very confused. I'll check your version of RStudio and shiny.

markriseley commented 9 years ago

Hey I reinstalled your parcoords package and lo and behold it worked.

Not sure what happens but your code is good. Thanks and keep the html widgets coming, they are awesome!

On 18 February 2015 at 18:04, timelyportfolio notifications@github.com wrote:

When I run your example, it works perfectly with shiny in both the viewer, chrome, and Firefox with no changes to the code. Also, looking at the code it applies correctly the function to the value. Still very confused. I'll check your version of RStudio and shiny.

— Reply to this email directly or view it on GitHub https://github.com/timelyportfolio/parcoords/issues/3#issuecomment-74914336 .

timelyportfolio commented 9 years ago

So glad to hear. Would love to see your creations. Know there are lots of ways to improve this. Let me know.

markriseley commented 9 years ago

Sure, I'm just learning the ropes right now, will share when I have something decent.

On parcoords, two possible developments:

FYI if you want any input on other d3 work that would be fantastic to visualize in R/Shiny here are my top picks:

On 18 February 2015 at 22:21, timelyportfolio notifications@github.com wrote:

So glad to hear. Would love to see your creations. Know there are lots of ways to improve this. Let me know.

— Reply to this email directly or view it on GitHub https://github.com/timelyportfolio/parcoords/issues/3#issuecomment-74961190 .

dannyvolkaerts commented 3 years ago

Is it possible that this is still an issue? parcoords doesn't render in Shiny (but it works beautifully in RStudio viewer / localhost browser).