我正在使用绘图流,但是我需要删除x轴的第一个标记,当其他所有标记都在变化时,它保持固定。 我正在使用R Shiny
想法是在分钟和秒过去时显示并消除这些值
请,有没有办法删除这些?以下是可复制的代码和图像。
library(shiny)
library(plotly)
rand <- function() {
runif(1, min=1, max=9)
}
t <- format(Sys.time(), "%H:%M:%S")
ui <- fluidPage(
#includeCSS("styles.css"),
headerPanel(h1("Streaming in Plotly: Multiple Traces", align = "center")),
br(),
div(actionButton("button", "Extend Traces"), align = "center"),
br(),
div(plotlyOutput("plot"), id='graph')
)
server <- function(input, output, session) {
p <- plot_ly(
type = 'scatter',
mode = 'lines'
) %>%
add_trace(
x = c(t,t),
y = c(rand(),rand()),
line = list(
color = '#25FEFD',
width = 3
)
) %>%
add_trace(
x = c(t,t),
y = c(rand(),rand()),
line = list(
color = '#636EFA',
width = 3
)
) %>%
layout(
yaxis = list(range = c(0,10))
)
output$plot <- renderPlotly(p)
observeEvent(input$button, {
while(TRUE){
Sys.sleep(1)
t <- format(Sys.time(), "%H:%M:%S")
plotlyProxy("plot", session) %>%
plotlyProxyInvoke("extendTraces", list(x=list(list(t), list(t)),y=list(list(rand()), list(rand()))), list(1,2))
}
})
}
shinyApp(ui, server)