GithubHelp home page GithubHelp logo

shiny-websockets's People

Contributors

timelyportfolio avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

shiny-websockets's Issues

Not an issue - Need some guidance

Hi Kent,

I was trying to create crosshairs on a ggplot2 and this is the best I could come up with. Do you think we can achieve this using native R functions or do we have to resort of Javascript. Given your expertise in this field, was wondering if you could provide your views.

library(shiny)
library(ggplot2)
library(Cairo)   # For nicer ggplot2 output when deployed on Linux

# We'll use a subset of the mtcars data set, with fewer columns
# so that it prints nicely
mtcars2 <- mtcars[, c("mpg", "cyl", "disp", "hp", "wt", "am", "gear")]


ui <- fluidPage(
  fluidRow(
    column(width = 4,
           plotOutput("plot1", height = 300,
                      # Equivalent to: click = clickOpts(id = "plot_click")
                      hover = hoverOpts(id = "plot_hover", delayType = "throttle"),
           )
    )
  ),
  fluidRow(
    column(width = 6,
           h4("Hover Points"),
           verbatimTextOutput("hover_info")
    )
  )
)

server <- function(input, output) {
  output$plot1 <- renderPlot({
    ggplot(mtcars2, aes(wt, mpg)) + 
    geom_point()  + 
    geom_vline(xintercept = xdata(),colour="black", linetype = "longdash") +
    geom_hline(yintercept = ydata(),colour="black", linetype = "longdash") +
    scale_x_continuous(limit = c(0, 5)) +
    scale_y_continuous(limit = c(0, 35))  
  })


  xdata<-reactive({
    ifelse(!is.null(input$plot_hover$x), return(input$plot_hover$x), return(0))
  })

  ydata<-reactive({
    ifelse(!is.null(input$plot_hover$y), return(input$plot_hover$y), return(0))
  })


  output$hover_info <- renderPrint({
    input$plot_hover$x
  }) 
}

shinyApp(ui, server)

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.