rAmCharts4-shiny: Shiny bindings for using 'rAmCharts4' in Shiny

rAmCharts4-shinyR Documentation

Shiny bindings for using rAmCharts4 in Shiny

Description

Output and render functions for using the rAmCharts4 widgets within Shiny applications and interactive Rmd documents.

Usage

amChart4Output(outputId, width = "100%", height = "400px")

renderAmChart4(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

must be a valid CSS unit (like "100%", "400px", "auto") or a number, which will be coerced to a string and have "px" appended

expr

an expression that generates a chart with amBarChart, amHorizontalBarChart, amLineChart, amScatterChart, amRangeAreaChart, amRadialBarChart, amDumbbellChart, amHorizontalDumbbellChart, amGaugeChart, amPieChart, or amPercentageBarChart

env

the environment in which to evaluate expr

quoted

whether expr is a quoted expression

Examples

library(rAmCharts4)
library(shiny)
library(lubridate)

ui <- fluidPage(
  br(),
  fluidRow(
    column(
      width = 8,
      amChart4Output("linechart", height = "500px")
    ),
    column(
      width = 4,
      tags$fieldset(
        tags$legend("Chart data"),
        verbatimTextOutput("chartData"),
      ),
      tags$fieldset(
        tags$legend("Change"),
        verbatimTextOutput("chartChange")
      )
    )
  )
)

server <- function(input, output){

  set.seed(666)
  dat <- data.frame(
    date = ymd(180101) + months(0:11),
    visits = rpois(12, 20),
    x = 1:12
  )

  output[["linechart"]] <- renderAmChart4({
    amLineChart(
      data = dat,
      data2 = dat,
      xValue = "date",
      yValues = "visits",
      draggable = TRUE,
      chartTitle = amText(
        text = "Number of visits",
        color = "crimson",
        fontWeight = "bold",
        fontFamily = "cursive"
      ),
      xAxis = list(
        title = "Date",
        labels = amAxisLabels(rotation = -45),
        breaks = amAxisBreaks(timeInterval = "1 month")
      ),
      yAxis = "Visits",
      yLimits = c(0, 35),
      backgroundColor = "whitesmoke",
      tooltip = "[bold][font-style:italic]{dateX}[/]\nvisits: {valueY}[/]",
      Yformatter = "#",
      caption = amText(
        text = "[bold font-size:22]Year 2018[/]",
        color = "fuchsia"
      ),
      button = amButton(
        label = amText("Reset data", color = "black"),
        color = "seashell",
        position = 0.95
      ),
      theme = "dataviz")
  })

  output[["chartData"]] <- renderPrint({
    input[["linechart"]]
  })

  output[["chartChange"]] <- renderPrint({
    input[["linechart_change"]]
  })

}

if(interactive()) {
  shinyApp(ui, server)
}

rAmCharts4 documentation built on Sept. 22, 2022, 5:05 p.m.