0
光沢のあるsliderInputを使用して日付でアニメーション化された散布図を作成しようとしています。しかし、私は毎週の曜日のためのデータを持っていないし、当時のプロットは空白の灰色のボックスです。私のsliderinputが特定の曜日をスキップするようにする方法があるので、データがない日に空白のプロットを表示しないでください。私は例を挙げました。光沢のあるsliderInput skipping今週の曜日
library(shiny)
library(lubridate)
airqual <- airquality %>%
mutate(date = as.Date(paste(airquality$Month, airquality$Day,
sep = "-"), format = "%m-%d")) %>%
filter(wday(date) %in% c(1, 3, 4, 5, 6, 7))
animationOptions(loop = TRUE)
ui <- fluidPage(
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("date",
"The date",
min = min(airqual$date),
value = min(airqual$date),
max = max(airqual$date),
animate = TRUE
)),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
airqual %>%
filter(date == input$date) %>%
ggplot(aes(x = Ozone, y = Solar.R)) +
geom_point()
})
}
# Run the application
shinyApp(ui = ui, server = server)
しかしupdateSliderInputは非常に便利です見ていると、このコードは私のために動作しませんでした。 – Ben
日付の一部はこのコードで値が欠落していましたが、 'data !'の' filter'を調整するだけで済みます( '!!is.na(Ozone)&!is.na( Solar.R) ')。それは別のものでしたか? – user5029763
私は欠けているデータはドットがないプロットとして表示され、月曜日のときはプロットが灰色の正方形であると思います。私はこのコードでも空の灰色の四角形がまだ残っていることがわかりました。 – Ben