【发布时间】:2022-01-03 00:35:44
【问题描述】:
我想在两个绘图 (plotly) 中显示数据,并希望能够通过使用串扰在另一个绘图中显示一个绘图的选定点。可悲的是,我尝试的任何方法都不起作用。在服务器功能之外定义共享数据的解决方案不是一个选项,因为我的应用程序中的数据来自其他反应和输入。下面是一个代表。
library(shiny)
library(plotly)
ui <- fluidPage(
sliderInput("rows", label = "# Rows", min = 50, max = 150, value = 100),
plotlyOutput("scatter1"),
plotlyOutput("scatter2")
)
server <- function(input, output, session) {
iris_new <- reactive({
iris[1:as.numeric(input$rows),]
})
sd <- SharedData$new(iris_new)
output$scatter1 <- renderPlotly({
plot_ly(
sd,
x = ~Sepal.Length,
y = ~Sepal.Width,
color = ~Species,
type = "scatter",
mode = "markers"
)
})
output$scatter2 <- renderPlotly({
plot_ly(
sd,
x = ~Petal.Length,
y = ~Petal.Width,
color = ~Species,
type = "scatter",
mode = "markers"
)
})
}
shinyApp(ui, server)
我还尝试将SharedData$new(iris_new) 设为反应式,例如
iris_new <- reactive({
SharedData$new(iris[1:as.numeric(input$rows),])
})
并在plot_ly(...) 中使用iris_new(),但它也不能正常工作。我也试过sd$data(withSelection = T),但没有运气。奇怪的是,当我选择一个点时,它可以工作(尽管我不能再取消选择)。但是当我尝试选择多个点(我真正想要的)时,另一个情节没有反应。
我需要它来处理 plotly(而不是 d3scatter、scatterD3 等)!
【问题讨论】: