Open ghost opened 5 years ago
Hi,
I have tried below Shiny implementation of above plot
library(shiny)
library(rAmCharts)
require(purrr)
library(htmlwidgets)
library(shinyjs)
ui = fluidPage(
inlineCSS(" #slider {
margin-top: 20px;
}"),
inlineCSS("
.ui-slider .ui-slider-handle {
width: 3.2em!important;
text-align: center;
margin-left: -1.6em!important;
}"),
div(id="slider"), div(id="chart-container", div(id="chart-div")),
amChartsOutput("amPLot", height = "485px")
)
Data_DF = data.frame(x = c('A', 'B'), y1 = c(90, 100), z1 = c('X', 'Y'))
Data_DF1 = list(list('year' = 2003, 'images' = Data_DF),
list('year' = 2004, 'images' = Data_DF))
server = function(input, output, session) {
amChart_Plot = amSerialChart(categoryField = "x", precision = 2, rotate = TRUE, hideCredits = TRUE, addClassNames = TRUE, plotAreaBorderAlpha = 1, plotAreaBorderColor = '#000') %>%
setDataProvider(dataProvider = Data_DF1[[1]]$images, keepNA = TRUE) %>%
setBalloon(cornerRadius = 12, textAlign = "left", maxWidth = 1300) %>%
addListener(name = "init", expression = "function(e) {
$( '#slider' ).slider({
'min': 0,
'max': 1,
'create': function( event, ui ) {
var dataSet = Data_DF1[[1]];
$('#slider .ui-slider-handle').text(dataSet.year);
},
'slide': function( event, ui ) {
var dataSet = Data_DF1[[ui.value]];
e.chart.dataProvider = dataSet.images;
e.chart.validateData();
$(ui.handle).text(dataSet.year);
}
});
}")
amChart_Plot = amChart_Plot %>%
addGraph(valueField = paste("y", 1, sep = ""), fillAlphas = 0.6, bullet = "round", lineThickness = 0, type = 'column',
fixedColumnWidth = 80, bulletColor = "transparent")
amChart_Plot@valueAxes = list(list(
labelFunction = JS("function(value) {return value+'%';}"), position = 'bottom', titleBold = FALSE,
maximum = 100, minimum = 0, stackType = "regular"))
output$amPLot = renderAmCharts(amChart_Plot)
}
shinyApp(ui = ui, server = server)
However I failed to bring the Slder as in my original Post. Any help on how to correct above plot to bring slider and change the plot according to the Slider movement is highly appreciated.
Thanks,
Hi,
I have posted my question in State exchange, however unable to get any feedback.
I want to implement below AmChart implementation in R through rAmChart. In normal HTML page below works fine, however I want to have it within a Shiny app and there I stuck. Any help would be highly appreciated.
HTML
CSS
JS