问题描述
我正在编写带有闪亮的阳光图表的闪亮应用程序。
提供正确格式的数据框后,必须单击朝阳图以“向下钻取”。
是否可以模仿此鼠标的“ click”事件来控制诸如selectInput()之类的用户输入的“下钻”操作?
如何链接selectInput()使其也能控制闪亮的旭日形?也许某种类型的观察事件?感谢您的帮助。
这里是代表:
SELECT acc1.username,acc2.username FROM
accounts acc1
INNER JOIN friends ON acc1.id = friends.idUser
INNER JOIN accounts acc2 ON friends.idUserFriend = acc2.id
WHERE acc1.username = 'para'
解决方法
您可以使用level
参数指定应显示的级别。我下面的解决方案需要解决2个问题:
- 更改不是动态的(也许您可以使用
plotly.animate
找到解决方案或将其用作起点)
只需单击一下图, -
make_selection
就不会更新(也许您可以玩plotly_sunburstclick
事件来更新它
library(shiny)
library(plotly)
d <- data.frame(
ids = c(
"North America","Europe","Australia","North America - Football","Soccer","North America - Rugby","Europe - Football","Rugby","Europe - American Football","Australia - Football","Association","Australian Rules","Autstralia - American Football","Australia - Rugby","Rugby League","Rugby Union"
),labels = c(
"North<br>America","Football","American<br>Football","Australian<br>Rules","Rugby<br>League","Rugby<br>Union"
),parents = c(
"","","North America","Australia - Rugby"
),stringsAsFactors = FALSE
)
ui <- fluidPage(
mainPanel(
# would like to be able to override or mimic mouse click even with this user input
selectInput(
"make_selection",label = h5("Make selection:"),choices = c("all" = " ",setNames(nm = d$ids)),selectize = TRUE,selected = "all"
),plotlyOutput("p")
)
)
server <- function(input,output,session) {
output$p <- renderPlotly({
plot_ly(d,ids = ~ids,labels = ~labels,parents = ~parents,level = input$make_selection,type = 'sunburst') %>%
event_register("plotly_sunburstclick")
})
observeEvent(event_data("plotly_sunburstclick"),{
# get the name of the id and update "make_selection"
})
}
shinyApp(ui = ui,server = server)