timelyportfolio / sunburstR

R htmlwidget for interactive sunburst plots
http://timelyportfolio.github.io/sunburstR/articles/sunburst-2-0-0.html
Other
210 stars 123 forks source link

Browsable, renderUI or Sunburst? #34

Closed tyjselina closed 7 years ago

tyjselina commented 7 years ago

Based on this http://timelyportfolio.github.io/sunburstR/example_baseball.html example (use sunburst event), I want to wrapped it into an interactive shiny app (the click on within an interactive shiny app). What I did previously is put the (browsable function/tagList) into the renderUI function,

`output$sunburst = renderUI({tagList( sb, tags$div(id="games", style="margin-top:100px"), tags$script(HTML( sprintf( ' var action = %s;

function mouseovered(d){ var games = action.filter(function(evt){ return evt.event === d.join("-"); });

var div = document.getElementById("games"); div.innerHTML = games.map(function(game){ return [ "<a href=\'http://gd2.mlb.com/components/game/mlb/year_2016/month_08/day_25/", game.gameday_link, "\'>", game.gameday_link, "
" ].join(""); }).join("\n"); } ', jsonlite::toJSON(action, auto_unbox=TRUE, dataframe="row") ) )) )})`

It works fine. But after I updated the sunburst package from 0.6.2 to 0.6.3, the generated sunburst chart is not shown up in the app. So I am wondering which parts has change resulting in the in-compatible of browsable/sunburst with renderUI

My current shiny version is shiny_0.14, R and R studio version is 3.3.2 and 0.99.902

Many thanks

timelyportfolio commented 7 years ago

Changes in 0.6.3

In 0.6.3, sunburst changed to use d3r for the d3 dependency, but this did not seem to affect any shiny examples that I tried. Can you try?

library(shiny)
library(sunburstR)
library(htmltools)

# read in sample visit-sequences.csv data provided in source
#   https://gist.github.com/kerryrodden/7090426#file-visit-sequences-csv
sequences <- read.csv(
  system.file("examples/visit-sequences.csv",package="sunburstR")
  ,header = FALSE
  ,stringsAsFactors = FALSE
)

sb <- sunburst(sequences)

ui <- htmlOutput("sb")

server <- function(input, output, session) {
  output$sb <- renderUI(tagList(sb))
}

shinyApp(ui, server)

Errors in JavaScript console

Would you be able to open your broken example in Chrome/Firefox/Safari to inspect the JavaScript console for errors? Usually, F12 or CTRL + Shift + J will open the debugger window.

Better Way?

I thought I would add some thoughts on a better way to approach your objective, by using the add_shiny() function and rendering your UI/HTMLoutput separately from the sunburst chart. See shiny example for an illustration. Happy to help work through this if you like the idea.

tyjselina commented 7 years ago

Hello, the code doesn't work on my machine. Just want to confirm with you the shiny version of your machine?

timelyportfolio commented 7 years ago

@tyjselina,

shiny       * 1.0.1   2017-04-01 CRAN (R 3.3.3)  

but I think the issue might be htmltools. Will you update to the github version of that and see if there is any effect?

devtools::install_github("rstudio/htmltools")
tyjselina commented 7 years ago

Many thanks. That works perfect!

tyjselina commented 7 years ago

Just noticed one more thing, for the sunburst version of 0.6.4, it seems the legendOrder statement doesn't work on my computer, as if I click the checkbox, there is no text. For example(in the middle part), https://github.com/timelyportfolio/sunburstR/issues/17#issuecomment-225233554

Let me know if I need to do more update.

Thank you for your great work.

timelyportfolio commented 7 years ago

Darn I thought I tested but could have easily messed it up with new color functionality. I will check by next week and fix.

timelyportfolio commented 7 years ago

@tyjselina, thanks again for the report. I believe I have fixed the issue. Please let me know if it does not work as expected for you.

tyjselina commented 7 years ago

@timelyportfolio It stays the same for me, there is still no text. Any ideas?

timelyportfolio commented 7 years ago

Did you do a fresh install_github? Are you copy/pasting that example? If not could you post code?

tyjselina commented 7 years ago

Thank you! It works! Previously I reinstalled the package from the cran, so I think that's the reason why it doesn't work.

timelyportfolio commented 7 years ago

Great to hear. I will try to push to CRAN by end of week. Thanks again for the bug report.