Create Sunburst Plot In Shiny Using Html Instead Of Sunburstoutput
Dear members of the community, I am using the R package sunburstR in order to create a sunburst plot into Shiny. The code below works perfect and I am able to create the plot, howe
Solution 1:
@warmoverflow answer should work ok, but the code below will show some possibly more robust methods for achieving your objective. I will comment inline in the code to try to describe the approaches.
library(sunburstR)
sequences <- read.csv(
system.file("examples/visit-sequences.csv",package="sunburstR")
,header = FALSE
,stringsAsFactors = FALSE
)
sunburst(sequences)
option 1 - htmlwidgets::onRender
We can use htmlwidgets::onRender
to remove the legend after the sunburst is drawn.
htmlwidgets::onRender(
sunburst(sequences),
'
function(el,x){
d3.select(el).select(".sunburst-sidebar").remove()
}
'
)
option 2 - replace the sunburst_html function
htmlwidgets
allows the use of a custom html function to define the container for the htmlwidget
. We can see the function for sunburstR with sunburstR:::sunburst_html
. In this approach, we will replace sunburstR:::sunburst_html
with a custom html function without the legend.
library(htmltools)
sunburst_html <- function(id, style, class, ...){
tagList(
tags$div(
id = id, class=class, style = style, style="position:relative;"
,tags$div(
tags$div(class="sunburst-main"
, tags$div( class="sunburst-sequence" )
, tags$div( class="sunburst-chart"
,tags$div( class="sunburst-explanation", style ="visibility:hidden;")
)
)
# comment this out so no legend
#,tags$div(class="sunburst-sidebar"
# , tags$input( type ="checkbox", class="sunburst-togglelegend", "Legend" )
# , tags$div( class="sunburst-legend", style ="visibility:hidden;" )
)
)
)
}
# replace the package sunburst_html with our custom function
# defined above
assignInNamespace("sunburst_html", sunburst_html, "sunburstR")
sunburst(sequences)
Solution 2:
You can use Javascript to hide the legend. Add the following below menuItem
(remember to add a ,
after the menuItem
line
tags$head(tags$script(HTML("
$(document).ready(function(e) {
$('.sunburst-sidebar').hide();
})
")))
If you prefer, you can even completely remove it (change hide
to remove
).
Post a Comment for "Create Sunburst Plot In Shiny Using Html Instead Of Sunburstoutput"