有没有办法在 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"))