【发布时间】:2026-01-05 23:15:01
【问题描述】:
当我以闪亮的方式运行程序时,我得到了Error: Invalid input: time_trans works with objects of class POSIXct only。这是我在shiny 中的代码:
library(ggplot2)
library(Cairo) # For nicer ggplot2 output when deployed on Linux
library(shiny)
ui <- fluidPage(
fluidRow(
column(width = 4, class = "well",
h4("Brush and double-click to zoom"),
plotOutput("plot1", height = 300,
dblclick = "plot1_dblclick",
brush = brushOpts(
id = "plot1_brush",
resetOnNew = TRUE
))),
column(width = 6,
plotOutput("plot3", height = 300)
)))
server <- function(input, output) {
# -------------------------------------------------------------------
# Single zoomable plot (on left)
ranges <- reactiveValues(x = NULL, y = NULL)
output$plot1 <- renderPlot({
ggplot(sensor_online, aes(x= record_time, y= temperature)) +
geom_point() +
coord_cartesian(xlim = ranges$x, ylim = ranges$y, expand = FALSE)
})
# When a double-click happens, check if there's a brush on the plot.
# If so, zoom to the brush bounds; if not, reset the zoom.
observeEvent(input$plot1_dblclick, {
brush <- input$plot1_brush
if (!is.null(brush)) {
ranges$x <- c(brush$xmin, brush$xmax)
ranges$y <- c(brush$ymin, brush$ymax)
} else {
ranges$x <- NULL
ranges$y <- NULL
}})}
# -------------------------------------------------------------------
shinyApp(ui, server)
我应该在我的shiny 服务器中更正什么以使没有Error?
【问题讨论】:
-
你应该考虑给我们一个可重现的例子。只要您不提供“sensor_online”,您的代码就不起作用。根据您的变量名称,我想知道您是否使用 as.Date() 函数 正确定义了 record_time
-
你看到这个帖子了吗(*.com/questions/34058001/…)?
标签: r user-interface ggplot2 shiny posixct