我收到警告(警告:已删除2行,其中包含缺少值(geom_path)。),对于以下代码,我不希望这样做:
library(shiny)
library(ggplot2)
library(scales)
ui <- navbarPage("Test",tabPanel("Test_2",fluidPage(
fluidRow(
column(width = 12,plotOutput("plot",width = 1200,height = 600))
),fluidRow(
column(width = 12,sliderInput("slider",label = "Range [h]",min = as.POSIXct("2019-11-01 00:00"),max = as.POSIXct("2019-11-01 07:00"),value = c(as.POSIXct("2019-11-01 00:00"),as.POSIXct("2019-11-01 07:00"))))
))))
server <- function(input,output,session) {
df <- data.frame("x" = c(as.POSIXct("2019-11-01 00:00"),as.POSIXct("2019-11-01 01:00"),as.POSIXct("2019-11-01 02:00"),as.POSIXct("2019-11-01 03:00"),as.POSIXct("2019-11-01 04:00"),as.POSIXct("2019-11-01 05:00"),as.POSIXct("2019-11-01 06:00"),as.POSIXct("2019-11-01 07:00")),"y" = c(0,1,2,3,4,5,6,7))
observe({
len_date_list <- length(df$x)
min_merge_datetime <- df$x[1]
max_merge_datetime <- df$x[len_date_list]
updateSliderInput(session,"slider",min = as.POSIXct(min_merge_datetime),max = as.POSIXct(max_merge_datetime),timeFormat = "%Y-%m-%d %H:%M")
})
output$plot <- renderPlot({
in_slider_1 <- input$slider[1]
in_slider_2 <- input$slider[2]
ggplot(data=df,aes(x,y,group = 1)) +
theme_bw() +
geom_line(color="black",stat="identity") +
# geom_point() +
scale_x_datetime(labels = date_format("%m-%d %H:%M"),limits = c(
as.POSIXct(in_slider_1),as.POSIXct(in_slider_2)))
})
}
shinyApp(server = server,ui = ui)
“缺失值”似乎是一个普遍的问题,因为我发现了很多类似的问题。在this问题中,解释说它必须是轴的范围。因此,以我为例,我确定这是由于scale_x_datetime中的限制所致。
scale_x_datetime(labels = date_format("%m-%d %H:%M"),limits = c(
as.POSIXct(in_slider_1),as.POSIXct(in_slider_2)))
但是当使用scale.x_datetime时,例如as.POSIXct和滑块,我没有找到答案。
顺便说一句:如果我注释掉“ geom_point”,我还会收到类似的警告。