r - R闪亮:滑块输入与小时,反应和绘图之间的链接
问题描述
我没有成功在带小时的滑块输入和反应式之间建立链接,以更改我的情节中的小时范围......小时列的类型在我的脚本中是 hms,有人可以帮助我吗?非常感谢 :slight_smile:
library(shiny)
library(ggplot2)
library(dplyr)
library(shinyTime)
library(lubridate) #variable temps
route_fond_degre <- c(1:10)
vitesse_fond_noeuds <- c(2:11)
heure <- c("01:05:30","01:05:31","01:05:32","01:05:33","01:05:34","01:05:35","01:05:36",
"01:05:37","01:05:38","01:05:39")
df_test <- data.frame(heure, route_fond_degre, vitesse_fond_noeuds)
ui <- fluidPage(
sliderInput(inputId = "periode",
label = "Période",
min = as.POSIXct("10:00:00",format = "%H:%M:%S"),
max = as.POSIXct("23:00:00",format = "%H:%M:%S"),
value = c(as.POSIXct("10:00:00",format = "%H:%M:%S"), as.POSIXct("23:59:59",format = "%H:%M:%S")),
timeFormat = "%H:%M:%S"),
#le slider s'affiche bien mais pas de lien avec le plot
plotOutput("graph1")
)
server <- function(input, output) {
date_filtre <- reactive({
mini <- as.POSIXct(input$periode[1])
maxi <- as.POSIXct(input$periode[2])
#df_test <- df_test %>% filter(heure > hms("10:00:00")) # this works without sliderinput
data_sel <- df_test %>% filter(heure > mini & heure < maxi)
return(data_sel)
})
output$graph1 <- renderPlot({
g <- ggplot(date_filtre(), aes_string(x="heure", y = "route_fond_degre"))+
geom_point()
g
})
}
shinyApp(ui=ui, server=server)
解决方案
df_test$heure
也转向POSIXct
打字。
df_test$heure <- as.POSIXct(df_test$heure, format = '%T')
推荐阅读
- .net - Cometd/bayeux 客户端问题
- sql - 使用 SQL Server 2016 导入整个 json 文件目录
- git - Git 分支策略与实践 - 基于主分支项目的不同项目放入不同的分支而不是新的存储库
- scikit-learn - scikit-learn: how to predict new data if after one hot encoding it has fewer features than the training/testing sets
- html - How to remove the dead zone between input radio and its label
- sql - Find maximum after multiplying two columns from two different tables - SQL
- spring - 如何解决返回模式在 Spring Boot 中不起作用
- c# - 为什么迁移添加会创建空迁移文件?
- python - matplotlib 如何可视化散点图和绘图
- jquery - 从 hive 中的表中提取列会导致 NULL 表