Skip to content

Instantly share code, notes, and snippets.

@Arkoniak
Last active February 21, 2017 20:26
Show Gist options
  • Save Arkoniak/8191386f2e36309f694511dfd5bf0808 to your computer and use it in GitHub Desktop.
Save Arkoniak/8191386f2e36309f694511dfd5bf0808 to your computer and use it in GitHub Desktop.
Example of dygraph with percent formatted y axis.
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(dygraphs)
library(xts)
data <- xts(c(0.1, 0.523, 0.231, 0.78), as.Date("2017-01-01") + 0:3)
# Define UI for application that draws a dygraph
ui <- fluidPage(
# Application title
titlePanel("Test Dygraph"),
# Show a plot of the generated dygraph
mainPanel(
dygraphOutput("testPlot")
)
)
# Define server logic required to draw a dygraph
server <- function(input, output) {
output$testPlot <- renderDygraph({
res <- dygraph(data) %>%
dyAxis("y",
valueFormatter = "function(v){return (v*100).toFixed(1) + '%'}",
axisLabelFormatter = "function(v){return (v*100).toFixed(0) + '%'}")
res
})
}
# Run the application
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment