绝对面板内的 dygraph

dygraph inside an absolute panel

我的主面板中有一张传单地图,我想在 R shiny 应用程序的 absolutePanel 中放置一个 dygraph。 我的问题是我在 absolutePanel 中看不到 dygraph。

我的ui.R中的代码是这样的:

library(dygraphs)

absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
          draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
          width = 300, height = "auto",

          h2("Sensitivity Explorer"),
          sliderInput(inputId="year",
                      label="Select a forecast year",
                      value=2018, min=2018, max=2050),



          numericInput("months", label = "Months to Predict", 
                       value = 72, min = 12, max = 144, step = 12),
          selectInput("interval", label = "Prediction Interval",
                      choices = c("0.80", "0.90", "0.95", "0.99"),
                      selected = "0.95"),
          checkboxInput("showgrid", label = "Show Grid", value = TRUE),

          dygraphOutput("dygraph",width = '50%')

                    )

和我的 server.R :

library(dygraphs)
function(input, output, session) {

predicted <- reactive({
hw <- HoltWinters(ldeaths)
predict(hw, n.ahead = input$months, 
        prediction.interval = TRUE,
        level = as.numeric(input$interval))
})
output$dyngraph <- renderDygraph({
if (nrow(zipsInBounds()) == 0)
  return(NULL)
dygraph(predicted(), main = "Predicted Deaths/Month") %>%
  dySeries(c("lwr", "fit", "upr"), label = "Deaths") %>%
  dyOptions(drawGrid = input$showgrid)

 })
 }

确保先测试 null,还可以使用 req 来了解其工作原理,只需键入 ?req。还有它的 dyngraph 顺便说一句

rm(list = ls())
library(shiny)
library(dygraphs)
ui <- fluidPage(
        absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
                      draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
                      width = 300, height = "auto",

                      h2("Sensitivity Explorer"),
                      sliderInput(inputId="year",
                                  label="Select a forecast year",
                                  value=2018, min=2018, max=2050),



                      numericInput("months", label = "Months to Predict", 
                                   value = 72, min = 12, max = 144, step = 12),
                      selectInput("interval", label = "Prediction Interval",
                                  choices = c("0.80", "0.90", "0.95", "0.99"),
                                  selected = "0.95"),
                      checkboxInput("showgrid", label = "Show Grid", value = TRUE),

                      dygraphOutput("dyngraph",width = '50%')

        )

)



server <- function(input, output, session){

        zipsInBounds <- reactive({mtcars[0,0]})

        predicted <- reactive({
                req(input$interval)
                req(input$months)
                hw <- HoltWinters(ldeaths)
                predict(hw, n.ahead = as.numeric(input$months), 
                        prediction.interval = TRUE,
                        level = as.numeric(input$interval))
        })
        output$dyngraph <- renderDygraph({
                if (is.null(zipsInBounds()))
                        return()
                dygraph(predicted(), main = "Predicted Deaths/Month") %>%
                        dySeries(c("lwr", "fit", "upr"), label = "Deaths") %>%
                        dyOptions(drawGrid = input$showgrid)

        })


}
shinyApp(ui = ui, server=server)