【发布时间】:2021-10-12 14:55:39
【问题描述】:
我试图在我的 Shiny 应用程序中只为我的范围滑块选择唯一值。我可以使用 SliderTextInput 来做到这一点,但我正在努力寻找一种方法来为范围滑块做到这一点。请看下面的代码。有什么建议吗?
#Example dataframe:
df<- data.frame("ID" = c("001","001","001"), "date" = c("2020-07-01 01:00:00","2020-07-01 03:00:00","2020-07-01 06:00:00"))
library(shiny)
library(move)
library(amt)
library(tibble)
library(dplyr)
library(htmltools)
library(dygraphs)
library(ggplot2)
library(plotly)
library(shinythemes)
library(shinydashboard)
library(datetime)
library(shinyTime)
shinyServer(function(input, output, session) {
observeEvent(input$selectVariable, {
min<- min(as.POSIXct(df$date))
max<- max(as.POSIXct(df$date))
updateSliderTextInput(session, "month", choices = sort(unique(df$date)), selected = sort(unique(df$date)))
updateSliderInput(session, "falltime", min = min, max = max, value =sort(unique(as.POSIXct(df$date))), timezone = "MST")
})
})
shinyUI(navbarPage(
tabPanel("Analysis",
sidebarLayout(
sidebarPanel(width = 5,
selectInput("selectVariable", "Select an ID:",
choices = unique(df$ID)),
sliderTextInput("month",
"Date Range Correct:",
choices = sort(unique(df$date))), #This slider works with the expected behavior but I need it to be a range slider
sliderInput('falltime',"Slider Incorrect Date Range:", min = as.POSIXct("2020-01-01 00:00:00", tz = "MST"), max = as.POSIXct("2020-02-02 00:00:00", tz = "MST"),
value = c(as.POSIXct("2020-01-01 00:00:00", tz = "MST"),as.POSIXct("2020-02-01 00:00:00", tz = "MST"))#, step =
)), #Can't figure out how to make this slider select only unique values
mainPanel(h2("Uploaded Data")))
)
)
)
【问题讨论】:
-
好的,现在应该可以使用了
标签: r shiny shiny-server