Skip to content
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

Capture user input #16

Open
krose opened this issue Jul 28, 2017 · 3 comments
Open

Capture user input #16

krose opened this issue Jul 28, 2017 · 3 comments
Assignees

Comments

@krose
Copy link

krose commented Jul 28, 2017

Nice work on the package!

This is a feature request. It would be great if I could capture and save the user input from shinydrawr. I don't know much about JavaScript so I have no clue about the implementation of it, but it's a feature that would be really useful to me, as I could benchmark user assumptions with real data.

@nstrayer
Copy link
Owner

nstrayer commented Jul 28, 2017

It's your lucky day! This is already implemented. Just copy the following into a script and run run it and you should have a working demo. Currently it returns the drawn y-values corresponding the x-locations in your supplied data post your cutoff. Is this what you're looking for?

#
# A small demo app for the shinydrawr function
#
# devtools::install_github("nstrayer/shinysense")
library(shiny)
library(shinythemes)
library(shinysense)
library(tidyverse)


ui <- fluidPage(
  theme = shinytheme("flatly"),
  titlePanel("shinydrawr demo"),
  p("Try and guess the rest of the chart below"),
  hr(),
  fluidRow(
    column(width = 8,
           shinydrawrUI("outbreak_stats")),
    column(width = 3, offset = 1,
           h2("Drawn values:"), tableOutput("displayDrawn"))
  )
)


server <- function(input, output) {
  random_data <- data_frame(time = 1:30,
                            metric = time * sin(time / 6) + rnorm(30))

  #server side call of the drawr module
  drawChart <- callModule(
    shinydrawr,
    "outbreak_stats",
    data = random_data,
    draw_start = 15,
    x_key = "time",
    y_key = "metric",
    y_max = 20,
    y_min = -50
  )

  #logic for what happens after a user has drawn their values. Note this will fire on editing again too.
  observeEvent(drawChart(), {
    drawnValues = drawChart()

    drawn_data <- random_data %>%
      filter(time >= 15) %>%
      mutate(drawn = drawnValues)

    output$displayDrawn <- renderTable(drawn_data)
  })

}

# Run the application
shinyApp(ui = ui, server = server)

@krose
Copy link
Author

krose commented Jul 30, 2017

Almost there :) Let's say I wan't to plot the data as points and then get the user to draw the best fit, but with points as well. Is that possible?

I have two use cases:

  • If the user could add best fit points/line on the plot below.
  • The user could also just get an x value and then add their y value as a single point on the canvas (not for the whole range).
with(do.call(rbind, lapply(1:10,  function(x){data.frame(x = 1:10, y = 1:10 + rnorm(10, sd = 2))})), plot(x, y))

@nstrayer nstrayer self-assigned this Jul 31, 2017
@nstrayer
Copy link
Owner

Ah I see. That is a good idea and one I've been meaning to get around to. Tagging this with an enhancement tag and will hopefully get around to it soon enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants