hrbrmstr / taucharts

:bar_chart: An R htmlwidget interface to the TauCharts javascript library
http://rpubs.com/hrbrmstr/taucharts
Other
65 stars 10 forks source link

add support for returning legend items #75

Closed Tutuchan closed 4 months ago

Tutuchan commented 6 years ago

Hello,

I added some code so we can retrieve the value of the legend item after a click event. The Shiny input is the input specified in tauchart() with -legend added at the end (e.g. tauchart(inputId = "test") yields input[["test-legend"]]).

Please, let me know if you feel this is useful.

Some code to test:

library(shiny)
library(taucharts)

ui <- fluidPage(
  titlePanel("Hello Shiny!"),
  sidebarLayout(
    sidebarPanel(),
    mainPanel(
      tauchartsOutput(outputId = "tc"),
      h2("Selected"),
      textOutput(outputId = "leg")
    )
  )
)

server <- function(input, output) {

  output$tc <- renderTaucharts({
    tauchart(iris, inputId = "iris") %>%
      tau_point(x = "Petal.Width", y = "Sepal.Width", color = "Species") %>%
      tau_legend()
  })

  output$leg <- renderText(input[["iris-legend"]])
}

shinyApp(ui = ui, server = server)