Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Last active October 14, 2015 05:36
Show Gist options
  • Save jcheng5/e9c7c83cc0168a6fcf4c to your computer and use it in GitHub Desktop.
Save jcheng5/e9c7c83cc0168a6fcf4c to your computer and use it in GitHub Desktop.

Revisions

  1. jcheng5 revised this gist Aug 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dyselect.R
    Original file line number Diff line number Diff line change
    @@ -50,4 +50,4 @@ dyselect <- function(dygraphExpr) {
    shiny::runApp(shinyApp(ui, server), launch.browser = getOption("viewer", TRUE))
    }

    dyselect(dygraph(cbind(mdeaths, fdeaths)))
    dygraph(cbind(mdeaths, fdeaths)) %>% dyselect()
  2. jcheng5 created this gist Aug 13, 2015.
    53 changes: 53 additions & 0 deletions dyselect.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    library(shiny)
    library(dygraphs)

    # Helper function to present Shiny controls in a dialog-like layout
    dialogPage <- function(outputControl) {
    bootstrapPage(
    tags$style("
    html, body { width: 100%; height: 100%; overflow: none; }
    #dialogMainOutput { position: absolute; top: 10px; left: 10px; right: 10px; bottom: 40px; }
    #dialogControls {
    position: absolute; bottom: 0px; left: 0px; right: 0px; height: 40px;
    padding: 10px 10px 0 10px;
    background-color: #444; color: white;
    }"),
    tags$div(id = "dialogMainOutput", outputControl),
    tags$div(id = "dialogControls",
    textOutput("msg", inline = TRUE),
    actionButton("done", "Done", class = "btn btn-primary btn-xs pull-right")
    )
    )
    }

    dyselect <- function(dygraphExpr) {
    # See below for definition of dialogPage function
    ui <- dialogPage(
    dygraphOutput("plot", width = "100%", height = "100%")
    )

    server <- function(input, output, session) {
    # Show the plot... that's important.
    output$plot <- renderDygraph(dygraphExpr)

    # Show a message giving instructions, or showing how many
    # rows are selected
    output$msg <- renderText({
    validate(need(input$plot_date_window, message = FALSE))
    paste(
    format(as.POSIXct(input$plot_date_window)),
    collapse = " to "
    )
    })

    # When the Done button is clicked, return the brushed
    # rows to the caller.
    observeEvent(input$done, {
    stopApp(as.POSIXct(input$plot_date_window))
    })
    }

    shiny::runApp(shinyApp(ui, server), launch.browser = getOption("viewer", TRUE))
    }

    dyselect(dygraph(cbind(mdeaths, fdeaths)))