我想创建一个闪亮的绘图,只允许套索和矩形选择。这似乎可以使用plotly::config 来实现。但是,缩放仍然启用。有没有办法在创建绘图时默认选择套索,从而无法再放大?
所以我有两个目标:防止用户能够放大和(更重要的是)默认情况下预选择套索。
请参阅以下示例:
library(shiny)
library(ggplot2)
library(plotly)
ui <- fluidPage(
plotlyOutput("po")
)
server <- function(input, output, session) {
output$po <- renderPlotly({
p <- ggplot(iris)+geom_point(aes(x=Sepal.Width,y=Sepal.Length,color=Species))
p <- toWebGL(p)
# Something like
# Plotly.relayout(graphDiv, 'dragmode', 'lasso')
plotly::config(p, displaylogo = FALSE, modeBarButtonsToRemove = list(
"toImage",
"zoom2d",
"pan2d",
"zoomIn2d",
"zoomOut2d",
"autoScale2d",
"resetScale2d",
"hoverClosestCartesian",
"hoverCompareCartesian"
))
})
}
shinyApp(ui, server)
不幸的是,我不知道如何翻译这个想法,我在这里找到:https://community.plotly.com/t/any-way-to-choose-the-lasso-select-tool-programatically- with-api/7834
或者也许还有另一种可能的选择。
我们可以简单地只调用
layout(dragmode = "lasso")
任何绘图对象:
library(shiny)
library(ggplot2)
library(plotly)
ui <- fluidPage(
plotlyOutput("po")
)
server <- function(input, output, session) {
output$po <- renderPlotly({
p <- ggplot(iris)+geom_point(aes(x=Sepal.Width,y=Sepal.Length,color=Species))
p <- toWebGL(p)
plotly::config(p, displaylogo = FALSE, modeBarButtonsToRemove = list(
"toImage",
"zoom2d",
"pan2d",
"zoomIn2d",
"zoomOut2d",
"autoScale2d",
"resetScale2d",
"hoverClosestCartesian",
"hoverCompareCartesian"
)) |> layout(dragmode = "lasso")
})
}
shinyApp(ui, server)
运行
plotly::schema()
并导航 layout.layoutAttributes.dragmode.description
了解详细信息。