【发布时间】:2019-07-20 19:57:20
【问题描述】:
我有一个条形图,它是闪亮应用程序的一部分。我用 plotly 创建了它。我希望用户能够选择图表的一部分(单击),并在单击数据表时显示与图表该部分悬停文本中给出的值相对应的所有行。
到目前为止,我能够显示 event.data 的输出,这不是很有趣。如何显示原始表中的相关行?
library(plotly)
library(shiny)
ui <- fluidPage(
uiOutput("ChooserDropdown"),
plotlyOutput("plot2"),
DT::dataTableOutput("tblpolypDetail2")
)
server <- function(input, output, session) {
output$plot2 <- renderPlotly({
# use the key aesthetic/argument to help uniquely identify selected observations
#key <- row.names(mtcars)
browser()
p <- ggplot(iris,aes_string(iris$Species,input$Chooser)) + geom_col()
ggplotly(p,source = "subset") %>% layout(dragmode = "select")
})
output$tblpolypDetail2 <- renderDataTable({
event.data <- event_data("plotly_click", source = "subset")
print(event.data)
})
output$ChooserDropdown<-renderUI({
selectInput("Chooser", label = h4("Choose the endoscopic documentation column"),
choices = colnames(iris) ,selected = 1
)
})
}
shinyApp(ui, server)
【问题讨论】: