有没有办法保持我的视图(缩放级别/范围),在R中有光泽的情节,如图重新渲染?
我删除了选定值的绘图,之后绘图重新渲染(因为R?中没有删除痕迹)。然后我必须回到剧情中感兴趣的区域。这会大大减慢这个过程,有什么方法吗?
感谢。
library(shiny)
library(plotly)
library(dplyr)
ui <- fluidPage(
fluidRow(
column(12,plotlyOutput("plot"),
actionButton("addButton", "Save Edits"),
verbatimTextOutput("txtout1"),
verbatimTextOutput("txtout2"),
verbatimTextOutput("txtout3"))
)
)
server <- function(input, output, session) {
x<-c(1,2,3,4,5,6,7)
y<-c(10,10,30,40,50,60,70)
df<-data.frame(x,y)
vector.is.empty <- function(x) return(length(x) ==0 )
K <-reactive({
event_data("plotly_selected",source = "B")
})
M<-reactive({
K()[,c("x","y")]
})
values <- reactiveValues()
values$df <- data.frame(x = numeric(0), y = numeric(0))
newEntry <- observeEvent(K(),{
if(!vector.is.empty(K())){
new0 <- isolate(M())
isolate(values$df <- rbind(values$df, new0))
}
})
uval <- reactiveValues()
uval$df <- df
newEntry1 <- observeEvent({values$df},{
if(!vector.is.empty(K())){
new1 <- isolate(data.frame(values$df))
fnew1 <- filter(df, !(df$x %in% new1$x))
isolate(uval$df <- fnew1)
}
})
output$plot <- renderPlotly({
plot_ly(uval$df, x = x, y = y, mode = "markers",source="B") %>%
layout(title = "Original Plot", font=list(size=10))
})
addData <- observe({
if(input$addButton > 0) {
save_data <<- isolate(uval$df)
}
})
output$txtout1 <- renderPrint({
if(vector.is.empty(K())) "Click and drag across points" else M()
#nrow(df)
})
output$txtout2 <- renderPrint({
#nrow(uval$df)
uval$df
})
output$txtout3 <- renderPrint({
#nrow(values$df)
values$df
})
}
shinyApp(ui, server, options = list(display.mode = "showcase"))