2

ggplot2 で作成された時系列プロットが、shinydashbaord のパネルに表示されます。下のパネルを時系列プロットのズーム プロットにする必要があります。何らかの理由で、ズーム プロットに時系列プロットのデータまたは軸の値が表示されません。ここで何か助けていただければ幸いです。

以下の例では、サイドバーで設定された日付範囲を使用しています。この例で日付範囲が変更された場合、プロットは機能しません。私の実際の作業は日付にそれほど敏感ではありません。これはデモ用です。

library (shiny)
library (shinydashboard)
library (ggplot2)

header <- dashboardHeader(title = "Example")

sidebar <- dashboardSidebar(
 sidebarMenu(
   menuItem("Data Estimation", tabName = "tabset1",
      dateRangeInput("dates", 
                    "Date range for regression",
                    start = as.character(Sys.Date() - 495), 
                    end = as.character(Sys.Date() - 396))
)))

body <- dashboardBody(
 fluidRow(
  tabBox(id = "tabset1", height = "450px", width = "900px",
   tabPanel("Time Series Est", 
     plotOutput ("plot1", height = 400,
                 brush = brushOpts(
                   id = "plot1Brush",
                   resetOnNew = TRUE)))
)),
 fluidRow(
  tabBox(id = "tabset1", height = "450px", width = "900px",
   tabPanel("Zoom", 
     plotOutput ("plot2", height = 400)
))))

ui <- dashboardPage(skin = "blue", header, sidebar, body)

server <- function(input, output) ({

output$plot1 <- renderPlot({

dat <- data.frame(x = seq(1,100,1), y = seq(1,2000,20), z = seq(1,3000,30), dateTime = seq(input$dates[1], input$dates[2], 1))

p <- ggplot() +
 geom_line(data = dat, aes(x = dateTime, y = x, color = "x")) +
 geom_line(data = dat, aes(x = dateTime, y = y, color = "y")) +
 geom_line(data = dat, aes(x = dateTime, y = z, color = "z")) +
 scale_y_log10() +
 theme_bw()

print(p)

})

ranges2 <- reactiveValues(x = NULL, y = NULL)

observe({
 brush <- input$plot1Brush
 if (!is.null(brush)) {
  ranges2$x <- c(brush$xmin, brush$xmax)
  ranges2$y <- c(brush$ymin, brush$ymax)
}
else {
 ranges2$x <- NULL
 ranges2$y <- NULL
}
})


output$plot2 <- renderPlot({

if (!is.null(ranges2$x)) {
ranges2$x <- as.Date(ranges2$x, origin = "1970-01-01")
}

dat <- data.frame(x = seq(1,100,1), y = seq(1,2000,20), z = seq(1,3000,30), dateTime = seq(input$dates[1], input$dates[2], 1))

p <- ggplot() +
 geom_line(data = dat, aes(x = dateTime, y = x, color = "x")) +
 geom_line(data = dat, aes(x = dateTime, y = y, color = "y")) +
 geom_line(data = dat, aes(x = dateTime, y = z, color = "z")) +
 coord_cartesian(xlim = ranges2$x, ylim = ranges2$y) +
 scale_y_log10() +
 theme_bw()

print(p)

})

})

shinyApp(ui, server)
4

2 に答える 2

2

renderPlot() 式で、 を使用する代わりにprint(p)p

それは私のために働いた。

于 2016-01-08T21:41:11.803 に答える