# NOT RUN {
library(Rnvd3)
library(shiny)
dat <- reshape2::melt(
apply(HairEyeColor, c(1, 2), sum), value.name = "Count"
)
CSS <- HTML(
"body {
overflow: overlay;
}
/* style axis titles */
.nvd3 .nv-axis.nv-x text.nv-axislabel,
.nvd3 .nv-axis.nv-y text.nv-axislabel {
font-size: 3rem;
fill: red;
}
/* style the tooltip */
.nvtooltip .value {
color: red;
}
.nvtooltip .x-value {
color: green;
}
.nvtooltip .key {
color: blue;
font-style: italic;
}
"
)
ui <- fluidPage(
tags$head(tags$style(CSS)),
br(),
fluidRow(
column(
9,
rnvd3Output("mychart", width = "100%", height = "500px")
),
column(
3,
tags$h3("Chart state:"),
verbatimTextOutput("state")
)
)
)
server <- function(input, output, session){
output[["mychart"]] <- renderRnvd3({
multiBarChart(
dat, Count ~ Eye, "Hair", palette = "viridis",
xLabelsFontSize = "2rem", yLabelsFontSize = "2rem"
)
})
output[["state"]] <- renderPrint({
input[["mychart_state"]]
})
}
if(interactive()){
shinyApp(ui, server)
}
# }
Run the code above in your browser using DataLab