Giter Site home page Giter Site logo

Comments (6)

Djaiff avatar Djaiff commented on August 15, 2024

Hi,
I'm afraid of not to understand what you really want to do. Does your question deal with shiny reactivity or JavaScript listener ? Could you maybe give an illustrative example ?

from ramcharts.

happyshows avatar happyshows commented on August 15, 2024

Hi,

for example, you have the following code that will show up an alert prompt window when band is clicked.
addListener('clickBand', 'function(event) { alert('clicked on band !') }')

instead of showing an alert window, can this selected value be assigned to a session object?
See Interaction with Shiny section
http://rstudio.github.io/DT/shiny.html

I personally find such very useful because it allows me to link with other diagram/tables for drilling down.

from ramcharts.

Djaiff avatar Djaiff commented on August 15, 2024

Hi,

We can use the event properties of the listener functions and combine this with the JavaScript function "Shiny.onInputChange". You can refer to this for more details: https://ryouready.wordpress.com/2013/11/20/sending-data-from-client-to-server-and-back-using-shiny/.

This is a simple example in which we are able to get the value clicked. The "event" object is detailed in the official API (http://docs.amcharts.com/3/javascriptstockchart/AmSerialChart).

library(rAmCharts)
library(shiny)
library(pipeR)
shinyApp(
  ui = fluidPage(
    amChartsOutput(outputId = "chart"),
    fluidRow(
      column(width = 1, strong("Values: ")),
      column(width = 3, verbatimTextOutput("result"))
    )
  ),

  server = function(input, output) {
    output$chart <- renderAmCharts({
      # prepare data
      dp <- data.table(name = paste0('foo', 1:5),
                       income = round(rnorm(5, mean = 30000, sd = 2000)))
      # build the chart
      pipeline(
        amSerialChart(categoryField = 'name', dataProvider = dp),
        addGraph(type = 'column', valueField = "income", fillAlphas = .6),
        addListener(name = 'clickGraphItem',
                    expression = paste('function(event){',
                                       'Shiny.onInputChange(\'myValues\', event.item.values);',
                                       '}'))
      )
    })
    output$result <- renderPrint({
      input$myValues
    })
  }
)

I hope this will help.

from ramcharts.

happyshows avatar happyshows commented on August 15, 2024

It works, thanks

from ramcharts.

happyshows avatar happyshows commented on August 15, 2024

@Djaiff Could you help look into why below code didn't work? Thanks.
data("data_candleStick1")
amCandlestick(data = data_candleStick1, names = c("min", "begin", "end", "max")) %>%
addListener(name = 'clickItem', expression = "function(event){ alert('ok !'); }")

from ramcharts.

happyshows avatar happyshows commented on August 15, 2024

Nevermind, figured out the name has to be 'clickGraphItem' If you could provide more documentation on available names in ?addListener, it would be great.

from ramcharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.