The name of the click event input depends on the output name (input$sunburst2_click
for output$sunburst2
).
Please check the following:
library(shiny)
library(sunburstR)
sequences <- read.csv(
system.file("examples/visit-sequences.csv", package = "sunburstR"),
header = FALSE,
stringsAsFactors = FALSE
)[1:200,]
sequences2 <- read.csv(
system.file("examples/visit-sequences.csv", package = "sunburstR"),
header = FALSE,
stringsAsFactors = FALSE
)[201:400,]
ui <- fluidPage(sidebarLayout(
sidebarPanel(),
# plot sunburst
mainPanel(
sund2bOutput("sunburst"),
sund2bOutput("sunburst2"),
textOutput("selection"),
textOutput("selection2"),
textOutput("selectionLatest")
)
))
server <- function(input, output, session) {
#sunburst1
output$sunburst <- renderSund2b({
add_shiny(sund2b(sequences))
})
#sunburst2
output$sunburst2 <- renderSund2b({
add_shiny(sund2b(sequences2))
})
#sunburst click event
selection <- reactive({
input$sunburst_click
})
selection2 <- reactive({
input$sunburst2_click
})
latestClick <- reactiveVal()
observeEvent(input$sunburst_click, {
latestClick(input$sunburst_click)
})
observeEvent(input$sunburst2_click, {
latestClick(input$sunburst2_click)
})
output$selection <- renderText(paste("plot 1:", paste(selection(), collapse = " - ")))
output$selection2 <- renderText(paste("plot 2:", paste(selection2(), collapse = " - ")))
output$selectionLatest <- renderText(paste("plot 1 or 2:", paste(latestClick(), collapse = " - ")))
}
shinyApp(ui = ui, server = server)
Here the "official" example can be found.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…