dreamrs / apexcharter Goto Github PK
View Code? Open in Web Editor NEW:bar_chart: R Htmlwidget for ApexCharts.js
Home Page: https://dreamrs.github.io/apexcharter
License: Other
:bar_chart: R Htmlwidget for ApexCharts.js
Home Page: https://dreamrs.github.io/apexcharter
License: Other
This is really more of an enhancement but I think being able to simultaneously view bar and line charts would be a useful addition. I know plotly does this through the add_trace feature so I don't know if a similar aspect could be added here. Otherwise this package is gorgeous, this group continues to impress me with its creativity and design/detail.
Hi,
based on your example gapminder scatter plot example: https://dreamrs.github.io/apexcharter/articles/articles/advanced-configuration.html
I want to create a simple "one-line"- bubble chart inside a table where I would like to add a tooltip containing just the color indicator of the series and the x value.
Objective: Is there a way to replace "a:" with the series indicator like in the regular Apexchart tooltips?
current custom tooltip:
function({ series, seriesIndex, dataPointIndex, w }) {
console.log(w); return (
'<div>' +
'<div style = "padding: 5px;">' +
'<div class = "apexcharts-tooltip-y-group">' +
'<span class = "apexcharts-tooltip-text-label">' +
w.config.series[seriesIndex].data[dataPointIndex].label + ':' +
'</span>' +
'<span class = "apexcharts-tooltip-text-value">' +
Math.round(w.config.series[seriesIndex].data[dataPointIndex].x * 100, 2) + ' %' +
'</span>' +
'</div>' +
'</div>'
);
}
Hi pvictor,
Thanks a lot for your ongoing work on this library, it's super cool and useful!
I am having an issue trying to give name to y_axis where the text appears to be outside the plot boundary. Could you give me some help with this? Thanks!
Reproducible example and picture of the result:
df <- data.frame(time = c(2020, 2025, 2030, 2035, 2040),
x = c(-10.1, -20.3, -30.4, -40.7, -50.8),
y = c(-3.4, -6.7, -10.1, -13.6, -16.9),
z = c(-6.8, -13.6, -20.3, -27.1, -33.9))
apexchart() %>%
ax_chart(type = "bar") %>%
ax_plotOptions(bar = bar_opts(
horizontal = FALSE,
dataLabels = list(
position = "top"
)
)
) %>%
ax_grid(show = FALSE
) %>%
ax_series(list(
name = "x",
data = df$x),
list(name = "y",
data = df$y),
list(name = "z",
data = df$z)
) %>%
ax_xaxis(categories = df$time) %>%
ax_yaxis(show = TRUE,
title = list(text = "Some text in millions units"
)
) %>%
ax_title(text = "Comparison of drug resource utilization") %>%
ax_subtitle(text = "Inpatient, outpatient, emergency department")
Interestingly, the problem is only present when dealing with all negative values on y-axis.
When I specify a color (e.g. black - #000000), to dataLabels
, no plot is produced.
Example:
library(shiny)
library(apexcharter)
data("vaccines", package = "highcharter")
df <- vaccines %>% subset(year <= 1946)
ui <- fluidPage(
apexchartOutput("heatmap")
)
server <- function(input, output) {
output$heatmap <- renderApexchart({
apex(df, aes(year, state, fill = count), type = "heatmap") %>%
ax_chart(animations = list(enabled = FALSE)) %>%
ax_dataLabels(enabled = TRUE, style =list(colors = "#000000"))
})
}
shinyApp(ui = ui, server = server)
Hello! Many thanks for this package!
Is it possible to make bar charts or lines or dotted lines with error bars?
HI ApexCharter Team,
The type = "timeline" option is not working.
No output (read: plot) is displayed.
apexcharter package version: 0.1.8.90
RMarkdown package version: 2.5
R version. : 4.02
RStudio: version 1.4.904
Windows 10
I have sued the example from Github (see below):
library(apexcharter)
library(tidyverse)
data("presidential", package = "ggplot2")
apex(presidential,
mapping = aes(x = name, start = start, end = end),
type = "timeline")
Hi all,
It does not seem possible to create a series-specific chart type when using the apex()
function to map a data frame into series.
Is there some way to use the aes()
function to accomplish this?
I have tried to add a "type" mapping in the aes()
function but it seems to be ignored
Below is a small reproducible example. I create a stacked area chart and I want to put a point to display the combined total value.
data <- tibble::tibble(x = runif(10), y = runif(10), total = x + y, x_axis = 1:10) %>%
dplyr::mutate(dplyr::across(c(x,y,total), cumsum)) %>%
tidyr::pivot_longer(names_to = "series", values_to = "value", cols = c(x,y,total)) %>%
dplyr::arrange(series) %>%
dplyr::mutate(series_type = ifelse(series == "total", "scatter", "area"))
library(apexcharter)
apex(data, aes(x = x_axis, y = value, group = series, type = series_type)) %>%
ax_chart(stacked = TRUE)
Would it be possible to add something like an add_text
to complement add_vline
, add_hline
and add_point
? It seems like the annotations definitions in apexchart allow for a text label:
annotations: {
...
texts: [{
x: 0,
y: 0,
text: '',
textAnchor: 'start',
foreColor: undefined,
fontSize: '13px',
fontFamily: undefined,
fontWeight: 400,
appendTo: '.apexcharts-annotations',
backgroundColor: 'transparent',
borderColor: '#c2c2c2',
borderRadius: 0,
borderWidth: 0,
paddingLeft: 4,
paddingRight: 4,
paddingTop: 2,
paddingBottom: 2,
}],
...
}
I tried with ax_annotations (texts = list(list(...)))
, but to no avail:
library(ggplot2)
library(apexcharter)
data("economics", package = "ggplot2")
apex(
data = tail(economics, 200),
mapping = aes(x = date, y = uempmed),
type = "line"
) %>%
ax_annotations(
yaxis = list(list(
y = 11.897,
borderColor = "firebrick",
opacity = 1,
label = list(
text = "Mean uempmed",
position = "left",
textAnchor = "start"
)
))
) %>%
ax_annotations(
texts = list(list(
x = htmlwidgets::JS("new Date('1 Mar 2007').getTime()"),
y = 15,
text = "A Text Label"
))
)
Hi Victor,
just a small question. I really like the tooltips for many series and just want to adapt the value by either coloring red or green depending on the value being over 0 or add an up or down html icon to the tooltip. Where could i start? Because building the tooltip from scratch is quite a bit.
mtcars %>%
dplyr::select(mpg, qsec) %>%
dplyr::add_rownames("car") %>%
dplyr::mutate(diff_mpg = round(mpg - lag(mpg), 1), diff_qsec = round(qsec - lag(qsec), 1)) %>%
dplyr::select(car, diff_mpg, diff_qsec) %>%
tidyr::gather(var, value, -car) %>%
apexcharter::apex(type = "bar", apexcharter::aes(car, value, fill = var)) %>%
apexcharter::ax_plotOptions(bar = apexcharter::bar_opts(
horizontal = FALSE,
endingShape = "flat",
columnWidth = "70%",
dataLabels = list(
position = "top"
))
) %>%
list()
Thanks in Advance!
Hi,
I want to use the brush option in Apexchart. However the brush char is not shown.
See example code below.
_library(shiny)
library(apexcharter)
data("economics", package = "ggplot2")
ui <- fluidPage(
fluidRow(
column(
width = 8, offset = 2,
tags$h2("Apexchart brush example in Shiny", class = "text-center"),
apexchartOutput("brush_1"),
apexchartOutput("brush_2", height = "130px")
)
)
)
server <- function(input, output, session) {
output$brush_1 <- renderApexchart({
apex(
data = economics,
mapping = aes(x = date, y = psavert),
type = "line"
) %>%
ax_chart(
id = "target-chart",
toolbar = list(
autoSelected = "pan",
show = FALSE
)
)
})
output$brush_2 <- renderApexchart({
apex(
data = economics,
mapping = aes(x = date, y = psavert),
type = "line"
) %>%
ax_chart(
brush = list(
target = "target-chart", # <-- use target id here
enabled = TRUE
),
offsetY = -20,
selection = list(
enabled = TRUE, # <-- enable selection and define starting range
xaxis = list(
min = format_date(economics$date[1]),
max = format_date(economics$date[100])
)
)
) %>%
ax_xaxis(labels = list(show = FALSE)) %>%
ax_yaxis(labels = list(show = FALSE))
})
}_
Please advice what I need to do ?
Regards,
Miguel
I use apex to draw scatter plot. But strange thing happened.
The iris dataset has 150 records.
Using apex(iris,type = 'scatter', aes(x=Sepal.Length,y=Sepal.Width))
. the plot is right.
But if group var is added, and using apex(iris,type = 'scatter', aes(x=Sepal.Length,y=Sepal.Width,group=Species))
.
The scatters get few.
Is it a bug?
Hi,
No matter the value for apex(height = ...)
, the plot size does not change. Am I using the right argument or there is a bug?
Example:
library(shiny)
library(apexcharter)
data("vaccines", package = "highcharter")
df <- vaccines %>% subset(year <= 1946)
ui <- fluidPage(
radioButtons("height",
label = "Heatmap Height",
choiceNames = c("50px", "400px", "800px", "50%", "100%", "400", "1000"),
choiceValues = c("50px", "400px", "800px", "50%", "100%", 400, 1000)
),
apexchartOutput("heatmap")
)
server <- function(input, output) {
output$heatmap <- renderApexchart({
apex(df,
aes(year, state, fill = count),
type = "heatmap",
height = input$height) %>%
ax_chart(animations = list(enabled = FALSE)) %>%
ax_dataLabels(enabled = FALSE)
})
}
shinyApp(ui = ui, server = server)
Thanks !
Hi Victor,
I hope you have been well.
Is there any way to save an apexchart as an image?
Best,
Alik
Hi,
I want to create a plot (line and pionts) where the color of a point depends on a categorical variable and the line has a fixed color for example black.
In ggplot the code would be something like this:
ggplot(aes(x=date, y=value)) +
geom_point(aes(color = category)) +
geom_line(color = "black")
I have tried a similar approach using apexcharter but the ggplot approach does not work. See example below
apex(type = "scatter", mapping = aes(x=date, y= value, fill = category) %>%
add_line(mapping = aes(x=date, y= value))
Output:
No line is displayed., only the points.
Please advice how to create a plot similar like ggplot using apexcharter
Question:
How can you set the color of a line independent/separately from the color of points ?
Looking forward receiving advice.
Regards,
Miguel
Updating the maximum of the x-axis works perfectly fine in shiny (press the "Update Max" button), but updating the format of the x-axis label labels does not seem to work. Pressing the "Update Format" button does not redraw the graph, in fact, the graph disappears.
library(shiny)
library(apexcharter)
x <- seq(-3,3,length.out=100)
df <- data.frame(x, y=dnorm(x))
ui <- fluidPage(
actionButton("max", "Update Max"),
actionButton("format", "Update Format"),
apexchartOutput("plot")
)
server <- function(session, input, output) {
output$plot <- renderApexchart({
apex(data=df, type='spline', mapping=aes(x=x, y=y)) %>%
ax_xaxis(type='numeric',
labels = list(formatter = format_num(".1f"))
)
})
observeEvent(input$max, {
apexchartProxy("plot") %>%
ax_proxy_options(
list(
xaxis = list(max = 4)
)
)
})
observeEvent(input$format, {
apexchartProxy("plot") %>%
ax_proxy_options(
list(
xaxis = list(labels =
list(formatter = format_num(".2f"))
)
)
)
})
}
shinyApp(ui = ui, server = server)
Hi Victor,
Hope you had a good weekend.
I am having a problem when trying to round-up the numbers on the ticks on y-axis for better appearance. I use formatter option in ax_yaxis for that, and it seems that this function is affecting the apperance of tooltip numbers as well. Is there a way to keep the tooltip numbers unaffected here?
Example here:
df <- data.frame(time = c(2020, 2025, 2030, 2035, 2040),
x = c(-10.12, -20.33, -30.44, -40.75, -50.86),
y = c(-3.42, -6.73, -10.14, -13.65, -16.96),
z = c(-6.82, -13.63, -20.34, -27.15, -33.96))
apexchart(auto_update = FALSE) %>%
ax_chart(type = "bar") %>%
ax_plotOptions(bar = bar_opts(horizontal = FALSE,
dataLabels = list(
position = "top"
))) %>%
ax_grid(show = FALSE) %>%
ax_series(
list(name = "x",
data = df$x),
list(name = "y",
data = df$y),
list(name = "z",
data = df$z)
) %>%
ax_xaxis(
categories = df$time,
axisBorder = list(color = "black"),
axisTicks = list(show = TRUE)
) %>%
ax_yaxis(
show = TRUE,
axisTicks = list(show = TRUE,
color = "black"),
axisBorder = list(show = TRUE,
color = "black"),
labels = list(minWidth = 60,
formatter = JS(
"function (val){
return val.toFixed(0)
}"
)
),
title = list(
text = "Prevalence (Mn)",
style = list(fontSize = "14px",
fontWeight = "normal")
)
)
Thanks!
Best wishes,
Alik
Thank you for this beautiful package.
I was trying to follow the vignettes to learn more about the specifics of apexcharter, but "Advanced configuration examples" can not be knitted anymore, because unhcr_ts
appears to be missing. I have tried substituting this dataset for the included unhcr_popstats_2017, without any success.
It seems not possible to change the colors of the x/y grid lines (i.e. between the cells).
Example:
library(shiny)
library(apexcharter)
data("vaccines", package = "highcharter")
df <- vaccines %>% subset(year <= 1946)
ui <- fluidPage(
apexchartOutput("heatmap")
)
server <- function(input, output) {
output$heatmap <- renderApexchart({
apex(df,
aes(year, state, fill = count),
type = "heatmap") %>%
ax_chart(animations = list(enabled = FALSE)) %>%
ax_dataLabels(enabled=F) %>%
ax_grid(xaxis = list(lines = list(show = T)), yaxis = list(lines = list(show = T)), borderColor = "#FF0000")
})
}
shinyApp(ui = ui, server = server)
Hi Victor,
I am back with another potentially easy/silly question, hope you don't mind :)
I have data that is plotted in three categories x, y, z through different years on x-axis. Each category in turn consists of different subcategories. Ideally, I would like to make a faceted grouped and stacked plot similar to this , however I don't think it is possible with apexcharter.
Instead, I was thinking to allow user to click on a particular bar of interest which will zoom in and provide a breakdown of that particular category over the years. Could you help me with it please?
Here example data and code:
library(apexcharter)
library(dplyr)
library(shiny)
ui <-
fluidPage(apexchartOutput("main_chart"),
verbatimTextOutput("click1"),
apexchartOutput("secondary_chart"))
server <- function(input, output, session) {
df <- data.frame(
time = c(2020, 2025, 2030, 2035, 2040),
x1 = c(10.1, 20.3, 30.4, 40.7, 50.8),
y1 = c(3.4, 6.7, 10.1, 13.6, 16.9),
z1 = c(6.8, 13.6, 20.3, 27.1, 33.9),
x2 = c(20.1, 30.3, 40.4, 50.7, 60.8),
y2 = c(6.4, 12.7, 20.1, 26.6, 32.9),
z2 = c(12.8, 26.6, 40.3, 52.1, 66.9)
)
output$main_chart <- renderApexchart({
# summarise data by x, y, z
df_sum <- df %>% mutate(x = x1 + x2,
y = y1 + y2,
z = z1 + z2)
ax <- apexchart(auto_update = FALSE) %>%
ax_chart(type = "bar") %>%
ax_grid(show = FALSE) %>%
ax_series(
list(name = "x",
data = df_sum$x),
list(name = "y",
data = df_sum$y),
list(name = "z",
data = df_sum$z)
) %>%
ax_xaxis(categories = df_sum$time) %>%
ax_title(text = "Output of plot 1") %>%
set_input_click("click")
})
# I want the main chart to turn into a
# breakdown of category similar to this
# (only one chart has to be displayed at any given time)
# breakdown chart example
output$secondary_chart <- renderApexchart({
# need to generate data dynamically based on click?
df_breakdown <- df %>%
select(time, contains("x"))
ax <- apexchart(auto_update = FALSE) %>%
ax_chart(type = "bar") %>%
ax_grid(show = FALSE) %>%
ax_series(
#need to generate series dynamically based on click?
list(name = "x1",
data = df_breakdown$x1),
list(name = "x2",
data = df_breakdown$x2)
) %>%
ax_xaxis(categories = df_breakdown$time) %>%
ax_title(text = "Output of plot 2")
})
output$click1 <- renderPrint({
input$click
})
}
shinyApp(ui = ui, server = server)
Best,
Alik
I'd like to create a view using multiple radial bars.
I successfully generate it using the following code:
s <- c('S1','S2','S3','S4','S5','S6','S7')
t <- c('100','100','100','50','10','0','0')
c <- data.frame(s,t)
apexcharter::apex(data = c, type = "radial",
mapping = aes(x = seqs, y = t))
Output:
But when I try to use Full API I'm struggling to map the parameters.
The following code isn't working
apexcharter::apexchart() %>%
ax_chart(type = "radialBar") %>%
ax_plotOptions(radial = radialBar_opts(
size = 6
)) %>%
ax_series(
list(
data = t
)
) %>%
ax_xaxis(categories = s ) %>%
ax_subtitle(text = "")
I would appreciate any tip in where am I going wrong?
Hi,
the function set_input_click
captures click events. I see that apexcharts.js also allows mouse-over events (called mouseMove).
Can this be implemented in the apexcharter package, so that one can e.g., retrieve the x- and y-coordinates when hovering over a point in a scatterplot?
Many thanks!
Bernhard
Hi,
I'll start by saying thanks for your work creating the R wrapper for apexcharts.
I have two donut charts that display different perspectives of the same reactive data i.e Owner & Type. I'm trying to make them interactive with each other so that when one is selected it filters the other and vise versa. I'm using reactive values to filter the dataset being used by the charts.
The problem I'm having is two fold:
By setting apexcharter's set_input_click() I'm able to retrieve the donut segment that is selected by the user. I'm however struggling to work out how to determine when the segment is unselected by a user. The click isn't firing an update to the input value i.e input$click <-NA or NULL
With the charts setup with the reactive data, I've got it setup to change the data being passed to the apexchart object (incl. the series colours). I however cannot seem to figure out how to get the legend to refresh. I've tried the config_update options with no luck.
I'm not sure if I'm overlooking something with these two things, any help would be appreciated!
Hi Victor,
I hope you had a good weekend!
I am trying to restrict the number of dataLabels I have on my barchart, but I can't make maxItems to work. Can you advise if this approach is incorrect when trying to make only a few datalabels to render? For example, ideally, I would like the dataLabels to render only on years 2020, 2025, 2030, 2035, 2040. Is it possible to do in apexcharter?
Here is a repex:
library(dplyr)
library(apexcharter)
df <- data.frame(
time = c(2020:2040),
x = runif(21, 50, 100),
y = runif(21, 50, 100),
z = runif(21, 50, 100),
a = runif(21, 50, 100),
b = runif(21, 50, 100)
) %>%
mutate_at(vars(x:b), funs(round(.,1)))
apexchart(auto_update = FALSE) %>%
ax_chart(type = "bar", stacked = TRUE) %>%
ax_plotOptions(bar = bar_opts(horizontal = FALSE,
columnWidth = "95%",
dataLabels = list(maxItems = 5) )
) %>%
ax_grid(show = FALSE) %>%
ax_series(list(name = "x",
data = df$x),
list(name = "y",
data = df$y),
list(name = "z",
data = df$z)) %>%
ax_xaxis(categories = df$time)
Hi Victor,
I hope you have been well!
I want the plots to re-render when the user switches between the radio buttons in shiny. The plots animate just fine on first render, but if you keep switching between the options, the plots do not animate again.
Is there a way to make them animate when flicking between the radio buttons?
library(apexcharter)
library(dplyr)
library(shiny)
ui <-
fluidPage(
radioButtons(
"radio_output_type",
label = "Select Complication:",
choices = list("One", "Two"),
selected = "One"
),
uiOutput("ui_main_chart")
)
server <- function(input, output, session) {
df <- data.frame(
time = c(2020, 2025, 2030, 2035, 2040),
x = c(10.1, 20.3, 30.4, 40.7, 50.8),
y = c(3.4, 6.7, 10.1, 13.6, 16.9),
z = c(6.8, 13.6, 20.3, 27.1, 33.9)
)
output$ui_main_chart <- renderUI({
if (input$radio_output_type == "One") {
apexchartOutput("plot1", height = "550px")
}
else if (input$radio_output_type == "Two") {
apexchartOutput("plot2", height = "550px")
}
})
output$plot1 <- renderApexchart({
aplot1 <- apexchart() %>%
ax_chart(type = "bar") %>%
ax_grid(show = FALSE) %>%
ax_series(list(name = "x",
data = df$x),
list(name = "y",
data = df$y),
list(name = "z",
data = df$z)) %>%
ax_xaxis(categories = df$time) %>%
ax_yaxis(
show = TRUE,
labels = list(minWidth = 60),
title = list(text = "Some text in millions units")
) %>%
ax_title(text = "Output of plot 1")
return(aplot1)
})
output$plot2 <- renderApexchart({
df <- df %>% filter(time != 2020)
aplot2 <- apexchart() %>%
ax_chart(type = "bar") %>%
ax_grid(show = FALSE) %>%
ax_series(list(name = "x",
data = df$x),
list(name = "y",
data = df$y),
list(name = "z",
data = df$z)) %>%
ax_xaxis(categories = df$time) %>%
ax_yaxis(
show = TRUE,
labels = list(minWidth = 60),
title = list(text = "Some text in millions units")
) %>%
ax_title(text = "Output of plot 2")
return(aplot2)
})
}
shinyApp(ui = ui, server = server)
Hi Victor,
The apexcharter v0.1 basic initial example
just hangs/freezes Rstudio ,
no plot is displayed:
library(apexcharter)
data("mpg", package = "ggplot2")
n_manufac <- dplyr::count(mpg, manufacturer)
n_manufac
manufacturer n
1 audi 18
2 chevrolet 19
3 dodge 37
4 ford 25
5 honda 9
6 hyundai 14
7 jeep 8
8 land rover 4
9 lincoln 3
10 mercury 4
11 nissan 13
12 pontiac 5
13 subaru 14
14 toyota 34
15 volkswagen 27
head(mpg)
manufacturer model displ year cyl
1 audi a4 1.8 1999 4
2 audi a4 1.8 1999 4
3 audi a4 2 2008 4
4 audi a4 2 2008 4
5 audi a4 2.8 1999 6
6 audi a4 2.8 1999 6
apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
At this point, Rstudio will just hang (freezes).
Have to restart Rstudio manually...
my loaded packages, simply:
(.packages())
[1] "stats" "graphics" "grDevices"
[4] "utils" "datasets" "methods"
[7] "base"
What am I missing?.
I have the latest versions of
ggplot2, tibble. etc....
Apparently, the latest versions of "tibble"
have been breaking a lot of other packages...
(for ex: the great janitor pkg, just fixed for that same reason...).
SFd99
Ubuntu Linux 18.04, latest Rstudio and R 3.6.3
The placement (and/or labels) of the x-axis ticks are somewhat off in this plot of a normal distribution with mean 0 and standard deviation 0.1:
x <- seq(-0.3, 0.3, 0.01)
df <- data.frame(x=x, y=dnorm(x, mean=0, sd=0.1))
apex(data=df, aes(x,y), type='spline') %>%
ax_xaxis(type='numeric',
max=0.3,
range=0.6,
tickAmount=6,
labels=list(formatter=format_num(".2f"))
)
I can't quite figure out what's wrong in the code. I expect the upper bound to be 0.3, and ticks at (-0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3), with the plot centered over 0.0. The funny thing is that the x-value in the hover information is correct.
Thanks for all your great open source Shiny work.
When I run the following app (with both apexcharter and rhandsontable) and click on a cell in the handsontable, I get the following JavaScript error.
Uncaught TypeError: Cannot read property 'opts' of undefined
at getSelection (apexcharter.js:44)
at d (handsontable.full.min.js:34)
at HTMLDivElement.<anonymous> (handsontable.full.min.js:34)
at HTMLDivElement.o (handsontable.full.min.js:29)
library(shiny)
library(rhandsontable)
library(apexcharter)
ui <- fluidPage(
fluidRow(
column(
6,
rHandsontableOutput("handson_out")
),
column(
6,
apexchartOutput("apex_out")
)
)
)
server <- function(input, output, session) {
output$apex_out <- renderApexchart({
data("mpg", package = "ggplot2")
n_manufac <- dplyr::count(mpg, manufacturer)
apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
})
output$handson_out <- renderRHandsontable({
rhandsontable(
iris
)
})
}
shinyApp(ui, server)
It looks like this is a namespace issue between your getSelection()
function here:
Here is my session info:
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] apexcharter_0.1.6 rhandsontable_0.3.7 shiny_1.5.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 compiler_4.0.3 pillar_1.4.6 later_1.1.0.1 tools_4.0.3 packrat_0.5.0
[7] digest_0.6.27 jsonlite_1.7.1 lifecycle_0.2.0 tibble_3.0.4 gtable_0.3.0 pkgconfig_2.0.3
[13] rlang_0.4.8 cli_2.1.0 rstudioapi_0.12 yaml_2.2.1 fastmap_1.0.1 withr_2.3.0
[19] dplyr_1.0.2 generics_0.1.0 htmlwidgets_1.5.2 vctrs_0.3.4 grid_4.0.3 tidyselect_1.1.0
[25] glue_1.4.2 R6_2.5.0 fansi_0.4.1 ggplot2_3.3.2 purrr_0.3.4 magrittr_1.5
[31] scales_1.1.1 promises_1.1.1 htmltools_0.5.0 ellipsis_0.3.1 assertthat_0.2.1 mime_0.9
[37] xtable_1.8-4 colorspace_1.4-1 httpuv_1.5.4 munsell_0.5.0 crayon_1.3.4.9000
>
Hello dreamRs,
I face an issue with apex facet on shinyapps.
Here is a reprex.
# ------------------------------------------------------------------------
#
# Title : apexcharts facet example
#
# ------------------------------------------------------------------------
library(shiny)
library(apexcharter)
data("mpg", package = "ggplot2")
ui <- fluidPage(
fluidRow(
column(
width = 8, offset = 2,
tags$h2("Apexchart facet example in Shiny", class = "text-center"),
apexchartOutput("apex"),
)
)
)
server <- function(input, output, session) {
output$apex <- renderApexchart({
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_xaxis(labels = list(formatter = format_num(".0f"))) %>%
ax_labs(
title = "Facet wrap example",
subtitle = "mpg data from ggplot2",
x = "engine displacement, in litres",
y = "city miles per gallon"
) %>%
ax_facet_wrap(vars(drv), ncol = 2)
})
}
shinyApp(ui, server)
message :
Error: 'options' must be a fully named list, or have no names (NULL)
config :
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=French_France.1252
[2] LC_CTYPE=French_France.1252
[3] LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C
[5] LC_TIME=French_France.1252
attached base packages:
[1] stats graphics grDevices utils
[5] datasets methods base
other attached packages:
[1] shiny_1.6.0 apexcharter_0.3.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 jquerylib_0.1.4
[3] bslib_0.2.5.1 pillar_1.6.2
[5] compiler_4.0.3 later_1.2.0
[7] tools_4.0.3 digest_0.6.27
[9] jsonlite_1.7.2 lifecycle_1.0.0
[11] tibble_3.0.6 gtable_0.3.0
[13] pkgconfig_2.0.3 rlang_0.4.10
[15] DBI_1.1.1 cli_3.0.1
[17] rstudioapi_0.13 yaml_2.2.1
[19] fastmap_1.1.0 dplyr_1.0.6
[21] sass_0.4.0 generics_0.1.0
[23] vctrs_0.3.8 htmlwidgets_1.5.3
[25] grid_4.0.3 tidyselect_1.1.1
[27] glue_1.4.2 R6_2.5.0
[29] fansi_0.5.0 ggplot2_3.3.5
[31] purrr_0.3.4 magrittr_2.0.1
[33] scales_1.1.1 promises_1.2.0.1
[35] ellipsis_0.3.2 htmltools_0.5.1.1
[37] assertthat_0.2.1 mime_0.11
[39] colorspace_2.0-0 xtable_1.8-4
[41] httpuv_1.6.1 utf8_1.2.1
[43] munsell_0.5.0 cachem_1.0.5
[45] crayon_1.4.1
Supposing I'm trying to shade the 10% lower tail in a normal distribution. I though I could do that using type=area-spline
and specifying appropriate stops in the color gradient in ax_fill
. When shading exactly 50% of the distribution, this seems to work, using offset=50
:
library(apexcharter)
x <- seq(-3.5,3.5,length.out=100)
df <- data.frame(x=x, y=dnorm(x))
apex(
data = df,
mapping = aes(x=x, y=y),
type = 'area-spline'
) %>%
ax_xaxis(
type = 'numeric',
min = -4,
max = 4,
tickAmount=8
) %>%
ax_fill(
type='gradient',
gradient=list(
type='horizontal',
opacityFrom=1,
opacityTo=1,
colorStops = list(
list(offset=50, color="#FFFF00"), #yellow
list(offset=0, color="#FF9900") #orange
)
)
)
But how do I shade the lower 10%? Using list(offset=10, color="#FFFF00"), #yellow
does shade a smaller portion, but it doesn't correspond to 10% of the area. What is the relationship between the offset and the area that is colored? Probably something much simpler than I'm imagining. Finally, what if I want to shade three areas, i.e., the lower 10%, the middle 70%, and the upper 20%?
In a different vein, I also tried this approach using a fill
aesthetic (I was unsuccessful using fillColor
):
df <- data.frame(x=x, y=dnorm(x), z=1)
df$z[df$x>qnorm(0.025)] <- 2
apex(
data=df,
mapping=aes(x=x, y=y, fill=z),
type='area-spline'
) %>%
ax_xaxis(type='numeric') %>%
ax_fill(type="solid", colors=c("#FFFF00","#FF9900"))
This is close enough (although there is a white space), but in fact the x-axis got messed up (the graph is now centered at 1)! There is a warning to use complete
, but using it as in df <- complete(df, x, z)
didn't help either. I must be doing something wrong.
Hi ApexCharter Developer's team.
Can you please advice me how to order a bar chart output such that the bars are shown from large to small..
I have tried the following standard ggplot2 way of doing this (see below) but this does not work for apexcharter.
data("mpg")
n_manufac <- count(mpg, manufacturer) %>%
mutate(manufacturer = fct_reorder(manufacturer,n))
apex(data = n_manufac,
type = "bar",
mapping = aes(x = manufacturer, y = n))
Kind regards,
Miguel
Is there a way to change the color of the cells reaching the minimum value (white by default) when using a color gradient?
Example:
library(shiny)
library(apexcharter)
data("vaccines", package = "highcharter")
df <- vaccines %>% subset(year <= 1946)
ui <- fluidPage(
apexchartOutput("heatmap")
)
server <- function(input, output) {
output$heatmap <- renderApexchart({
apex(df,
aes(year, state, fill = count),
type = "heatmap") %>%
ax_chart(animations = list(enabled = FALSE)) %>%
ax_dataLabels(enabled=F) %>%
ax_colors("#0000FF") %>%
ax_plotOptions(heatmap = heatmap_opts(colorScale = list(min = min(df$count), max = max(df$count))))
})
}
shinyApp(ui = ui, server = server)
Submitting a minimum value below the actual dataset minimum value does not do the trick neither:
ax_plotOptions(heatmap = heatmap_opts(colorScale = list(min = min(df$count) - 1000, max = max(df$count))))
Hi,
I want to a vertical line on my apexchart using the add_vline() function.
My x-axis displays dates.
I have converted the date value for position of the vertical line into a numeric value (I think that this is required), however no vertical line is displayed on the chart.
See example code below:
apexcharter::add_vline(value = as.Date("2021-02-10") %>% as.numeric(),
dash = 4, color = "red", label = "Hello")
Please advice how to solve this problem.
Looking forward to hear from you soon.
Met vriendelijke groet,
Miguel
Hi,
First of all, thanks for this awesome package !
However, I am having issues customizing the tooltip when making stacked barcharts.
From the example given in the vignette:
library(ggplot2)
library(scales)
library(dplyr)
library(apexcharter)
data("mpg")
n_manufac_year <- count(mpg, manufacturer, year) %>%
group_by(manufacturer) %>%
mutate(pct = n/sum(n)*100)
apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = pct, fill = year)) %>%
ax_chart(stacked = TRUE)
How could one display tooltips formatted as below for instance (i.e. containing pct
and n
values):
dodge
1999: 43.2% (16)
2008: 56.8% (21)
I tried to include a custom formatter but I am afraid I do not get the JS logic
apex(data = n_manufac_year, type = "column", mapping = aes(x = manufacturer, y = pct, fill = year)) %>%
ax_chart(stacked = TRUE) %>%
ax_tooltip(
y = list(
formatter = JS("function(value) {return value + '%'}")
)
)
Getting a bar chart with different colored bars is harder than you think, and the end result is still not satisfying as it shows empty (NA) labels:
A natural (by ggplot2
standards) approach is to try:
library(apexcharter)
plotdata <- data.frame(x=c("a","b"), counts=5:6, color=1:2)
apex(
data = plotdata,
type = "column",
mapping = aes(x = x, y = counts, fill = color)
)
but this "drops" the b category and produces
One can complete the plotdata through
library(tidyr)
plotdata1 <- complete(plotdata, x, color)
and then get two different colors for the two bars
apex(
data = plotdata1,
type = "column",
mapping = aes(x = x, y = counts, fill = color)
)
but there are empty bars at each category on the x-axis (because of the NA's generated in complete
):
Ideally, I was hoping code like
apex(
data = plotdata,
type = "column",
mapping = aes(x = x, y = counts, fill = color)
) %>%
ax_colors(c("red","orange"))
would give two bars, the one over "a" in one red, the other over "b" in orange. Instead, I get:
But perhaps I don't quite understand how to get this with apexcharter.
Thanks!
Bernhard
Great development! I just wonder if there are ways to add confidence intervals into the plots?
Hi all,
I am creating an apexchart split into facets and I would like to add annotations to one specific sub-graph (facet).
However, adding a point annotation I see that it is added to all graphs.
Is there a way to add an annotation to a specific facet of the graph?
Below is a small reproducible example showing the behaviour.
Many thanks in advance
library(apexcharter)
apex(iris, aes(x = Sepal.Length, y = Sepal.Width), type = "scatter" ) %>%
ax_facet_wrap(facets = vars(Species)) %>%
ax_annotations(points = list(list(
x = 6,
y = 3,
marker = list(
size = 2,
fillColor = "red",
strokeColor = "red",
radius = 1
),
label = list(
text = "Test",
offsetY = 0,
borderColor = "#FF4560",
style = list(
color = "#fff",
background = "#FF4560"
)
)
)))
HI,
Does R Apexcharter support the Dynamic Series Update functionality (see example: https://github.com/apexcharts/apexcharts.js) ?
If so, could you provide me with an example how to use this with the R apexcharter package functions ?
Thanks in advance.
Miguel
Hi,
updating the color of a plot in shiny is not working, similar to other configuration like the stroke width.
It took me quite some time to figure out what causes this issue:
Although auto_update
is set to TRUE as default in the apexchart
function, the parameter fig$x$auto_update$update_options
is FALSE after creating the plot.
This causes that updating the color palette based on some shiny input variable (i.e. number of series) is not applied although the data update is performed correctly within shiny. I am doing that to apply a specific color to a specific data series if selected from an input.
The following code structure leads to the issue:
output$kpi_area_chart <- apexcharter::renderApexchart({
... some logical modifying the color pallete...
fig <- apexcharter::apexchart(ax_opts = list(
... chart config...
colors = my_chaged_color_palette,
))
})
fig
When changing the paramater the color palette will not change although the parameter has changed.
For now, a solution is adding
fig$x$auto_update$update_options <- TRUE
I have a dataset showing cases by week ending date (epi curve), and I want the labels to be at each date with a tick mark right in the middle of the bar chart. Having trouble figuring it out, any help is appreciated.
Hi! Thank you for this great job !
Can you add support for sunburst plots ?
Hi, is there any way that we could generate a box plot using the apexcharter interface? If not, would you mind providing an example of using R to interact with the raw apexchart API to create a boxplot? Thanks!
I plan to use your package in a shiny app, where I need to visualize the effects of a variable with many factor levels (20-30). In this context it's important, that the colors for the specific factor levels don't change when some kind of filter or drill down happens.
In ggplot2 this can be achieved by setting scale_color_discrete(drop = FALSE)
. Is there a similar solution that can be used or implemented in the apexcharter package (potentially ax_colors(drop = FALSE)
or so)?
By the way, the package has been a deligth to use so far! :)
library(tidyverse)
library(apexcharter)
mtcars_fct <- mtcars %>%
modify_at("cyl", factor)
mtcars_fct %>%
filter(cyl != "4") %>%
ggplot(aes(wt, mpg, color = cyl)) +
geom_point() +
scale_color_discrete(drop = FALSE)
mtcars %>%
filter(cyl != "4") %>%
apex(type = "scatter",
mapping = aes(x = wt, y = mpg, fill = cyl))
Created on 2020-07-27 by the reprex package (v0.3.0)
Hi,
I have added tooltips to my chart and although they look very nice, I'd like them to display more information than the current default. At the moment they simply show the x- & y-values of each observation. Is there a way of including more variables in the display than that? I have a character column in my dataframe which I'd like to include in the tooltip, but so far the only further customization option I found is recreating the entire tooltip with HTML.
Thank you again for this package, it really is a great charting tool.
Hi Victor,
I hope you have been well. Thank you for the recent update to the package! The candlestick functionality comes at a perfect timing of needing to integrate a waterfall chart in my shiny app. And since I am using apexcharter exclusively for my plots, it would be great for me to try to make it by adjusting the candlestick plot you recently added.
My question is the following: having never dealt with candlestick plots before, I understand that the data structure needs to be slightly different. Could you please give a basic example of how the data and the chart code supposed to look like?
Best,
Alik
Really been enjoying this package as it keeps maturing, so just wanted to say thanks first!
I've created a minimal Shiny app with the Brush Chart example on your package's github.io
, but the 2nd chart (w/ brush: enabled=TRUE
) doesn't show up until I open the browser's devtools. When I open it in Chrome, I'm getting the error TypeError: Cannot read property 'w' of undefined
.
Reprex:
global.R
library(shiny)
library(apexcharter)
data("economics", package = "ggplot2")
server.R
server <- function(input, output, session) {
output$brush_1 <- renderApexchart({
apex(
data = economics,
mapping = aes(x = date, y = psavert),
type = "line"
) %>%
ax_chart(
id = "target-chart", # <-- define target id here
toolbar = list(
autoSelected = "pan",
show = FALSE
)
)
})
output$brush_2 <- renderApexchart({
apex(
data = economics,
mapping = aes(x = date, y = psavert),
type = "line",
height = "130px"
) %>%
ax_chart(
brush = list(
target = "target-chart", # <-- use target id here
enabled = TRUE
),
offsetY = -20,
selection = list(
enabled = TRUE, # <-- enable selection and define starting range
xaxis = list(
min = format_date(economics$date[1]),
max = format_date(economics$date[100])
)
)
) %>%
ax_xaxis(labels = list(show = FALSE)) %>%
ax_yaxis(labels = list(show = FALSE))
})
}
ui.R
ui <- fluidPage(
fluidRow(
column(
12,
apexchartOutput("brush_1"),
apexchartOutput("brush_2")
)
)
)
Oddly enough, the exact same chart works locally in another app of mine, but then once it's deployed to shinyapps.io or a GCP VM Instance, the same console error occurs.
Here's my session info (GithubSHA1: bd179f978b27fb34e9ac5b8a206339fdb5465bbf
):
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.5
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
character(0)
other attached packages:
[1] apexcharter_0.1.5
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 pillar_1.4.6 compiler_3.6.3 later_1.1.0.1 methods_3.6.3 utils_3.6.3
[7] tools_3.6.3 grDevices_3.6.3 digest_0.6.25 packrat_0.5.0 jsonlite_1.7.0 lifecycle_0.2.0
[13] tibble_3.0.3 gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.7 shiny_1.5.0 cli_2.0.2
[19] rstudioapi_0.11 yaml_2.2.1 fastmap_1.0.1 withr_2.2.0 dplyr_1.0.0 generics_0.0.2
[25] graphics_3.6.3 vctrs_0.3.2 htmlwidgets_1.5.1 datasets_3.6.3 stats_3.6.3 grid_3.6.3
[31] tidyselect_1.1.0 glue_1.4.1 base_3.6.3 R6_2.4.1 fansi_0.4.1 ggplot2_3.3.2
[37] purrr_0.3.4 magrittr_1.5 scales_1.1.1 promises_1.1.1 ellipsis_0.3.1 htmltools_0.5.0
[43] assertthat_0.2.1 mime_0.9 xtable_1.8-4 colorspace_1.4-1 httpuv_1.5.4 munsell_0.5.0
[49] crayon_1.3.4
Hi great idea to port apexchart.js! I switched all my stuff from highcharts to apex, thanks for that. I wonder whether it is possible to get a shiny input value when the plot is clicked? I did not find anything on that subject. Best, Simon
Hi thanks for the excellent package. I am very excited about using these charts in more of my Shiny apps.
For some odd reason my charts keep increasing in height. Please see a minimal examples below. Whenever I open the pickerInput()
the chart increases in height a little bit. I found this possibly related issue in apexcharts: apexcharts/apexcharts.js#460 . But I was not able to use the fix from that issue to resolve the issue in Shiny.
library(shiny)
library(apexcharter)
ui <- fluidPage(
fluidRow(
column(
12,
shinyWidgets::pickerInput(
"open_me",
"Open Me",
choices = c("choice A")
)
)
),
fluidRow(
column(
12,
apexchartOutput("apex_chart")
)
)
)
data("mpg", package = "ggplot2")
n_manufac <- dplyr::count(mpg, manufacturer)
server <- function(input, output, session) {
output$apex_chart <- renderApexchart({
apex(data = n_manufac, type = "bar", mapping = aes(x = manufacturer, y = n))
})
}
shinyApp(ui, server)
The issue is occurring with both the CRAN version 0.1.1 and the development version from GitHub. Below is my sessionInfo using the CRAN version.
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] apexcharter_0.1.1 shiny_1.3.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 rstudioapi_0.10 magrittr_1.5
[4] tidyselect_0.2.5 munsell_0.5.0 colorspace_1.4-1
[7] xtable_1.8-4 R6_2.4.0 rlang_0.4.0
[10] dplyr_0.8.3 shinyWidgets_0.4.8 tools_3.6.1
[13] grid_3.6.1 packrat_0.5.0 gtable_0.3.0
[16] htmltools_0.3.6 yaml_2.2.0 assertthat_0.2.1
[19] lazyeval_0.2.2 digest_0.6.20 tibble_2.1.3
[22] crayon_1.3.4 purrr_0.3.2 ggplot2_3.2.1
[25] later_0.8.0 htmlwidgets_1.3 promises_1.0.1
[28] glue_1.3.1 mime_0.7 compiler_3.6.1
[31] pillar_1.4.2 scales_1.0.0 jsonlite_1.6
[34] httpuv_1.5.1 pkgconfig_2.0.2
Hi, big fan of the package, encountered one issue so far -- whenever the x axis is date, there are problems. For scatter/line plot, the date will show up, but it's not lining up with the ticks, so I need to adjust the timezone (for my case it's from EST to GMT); and for barcharts, date can't simply be displayed, instead it's the numeric value of timestamp. I wonder if you had similar issues before, would really appreciate it if this could be addressed to some extent!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.