-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement stacked bar chart #4
Comments
|
@ChiragJhawar This is finished. Here is a Shiny example with an 'Update' button:
|
Hmm I'm not sure this is possible. I will think about it. |
I think this is not possible by dragging (or highly complicated). But you could use some Shiny sliders, as in the following example. library(shiny)
library(rAmCharts4)
probs <- c(control = 30, treatment = 75)
ui <- fluidPage(
br(),
sidebarLayout(
sidebarPanel(
wellPanel(
tags$fieldset(
tags$legend("Survival probability"),
sliderInput(
"control",
"Control group",
min = 0, max = 100, value = probs[["control"]], step = 1
),
sliderInput(
"treatment",
"Treatment group",
min = 0, max = 100, value = probs[["treatment"]], step = 1
)
)
)
),
mainPanel(
amChart4Output("barchart", width = "500px", height = "400px")
)
)
)
server <- function(input, output, session){
dat <- data.frame(
group = c("Control", "Treatment"),
alive = c(probs[["control"]], probs[["treatment"]]),
dead = 100 - c(probs[["control"]], probs[["treatment"]])
)
stacks <- list(
c("alive", "dead")
)
seriesNames <- list(
alive = "Alive",
dead = "Dead"
)
output[["barchart"]] <- renderAmChart4({
amStackedBarChart(
dat,
category = "group",
stacks = stacks,
seriesNames = seriesNames,
yLimits = c(0, 100),
chartTitle = amText(
"Survival probabilities",
fontFamily = "Trebuchet MS",
fontSize = 30,
fontWeight = "bold"
),
xAxis = "Group",
yAxis = "Probability",
theme = "dataviz"
)
})
observeEvent(list(input[["control"]], input[["treatment"]]), {
newdat <- data.frame(
group = c("Control", "Treatment"),
alive = c(input[["control"]], input[["treatment"]]),
dead = 100 - c(input[["control"]], input[["treatment"]])
)
updateAmBarChart(session, "barchart", newdat)
})
}
shinyApp(ui, server) |
Hello, sorry for the delayed response. I was off of this for sometime. Thank you so much for this. This seems a lot of hard work and effort and it's amazing. Is there absolutely no way thaat we could make the main (control/treatment) graphs draggable? This is why I was thinking that overlapping the renders would be a nice idea if it were possible. |
Hi, do you have experience using r2d3? if yes, is it possible to implement https://bl.ocks.org/AlainRo/9264cd08e341f2c92f020c39642c34d1 in that. I have tried to use this, it prints only the background and not the data itself. It's because in D3, we can render graphs on one another which would solve my problem. Thanks. |
See stacked-clustered-column-chart.
The text was updated successfully, but these errors were encountered: