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

Add assistant #17

Open
bedantaguru opened this issue Feb 12, 2020 · 3 comments
Open

Add assistant #17

bedantaguru opened this issue Feb 12, 2020 · 3 comments
Labels
Enhancement New feature or request Kept for Later This will be implemented in future is required

Comments

@bedantaguru
Copy link
Member

At least for Proof of Concept add a simple assistant

  • This should work automatically in Rstudio only.
  • It should work when the package is loaded.
  • Basically it is an overview in the viewer

Create a broader framework if found to be useful.

@bedantaguru bedantaguru added Enhancement New feature or request Kept for Later This will be implemented in future is required labels Feb 12, 2020
@bedantaguru
Copy link
Member Author

See this code as a proof of concept.

However, it seems this is not a good idea to have this feature unless there is a programmatic deletion option available from the viewer.

I have raised this SO for knowledge acquisition if any solution exists and has raised and issue rstudio/rstudioapi#169.

For the time being, I am not working on it and keeping it open for future versions.

@bedantaguru
Copy link
Member Author

Here is what I found

library(shiny)

# Define UI for app that draws a histogram ----
ui <- fluidPage(

  # App title ----
  titlePanel("Hello Shiny!"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel for inputs ----
    sidebarPanel(

      # Input: Slider for the number of bins ----
      sliderInput(inputId = "bins",
                  label = "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)

    ),

    # Main panel for displaying outputs ----
    mainPanel(

      # Output: Histogram ----
      plotOutput(outputId = "distPlot")

    )
  )
)

# Define server logic required to draw a histogram ----
server <- function(input, output) {

  # Histogram of the Old Faithful Geyser Data ----
  # with requested number of bins
  # This expression that generates a histogram is wrapped in a call
  # to renderPlot to indicate that:
  #
  # 1. It is "reactive" and therefore should be automatically
  #    re-executed when inputs (input$bins) change
  # 2. Its output type is a plot
  output$distPlot <- renderPlot({

    x    <- faithful$waiting
    bins <- seq(min(x), max(x), length.out = input$bins + 1)

    hist(x, breaks = bins, col = "#75AADB", border = "white",
         xlab = "Waiting time to next eruption (in mins)",
         main = "Histogram of waiting times")

  })

}

# Create Shiny app ----

#runApp(shinyApp(ui = ui, server = server), port = 6833L)

# nb : non blocking
# sa = shinyApp(ui = ui, server = server)
runApp_nb <- function(sa, pin_port = NULL){


  viewer <- getOption("viewer")
  if(!is.null(viewer)){

    if(!is.null(pin_port) && is.integer(pin_port)){
      port <- pin_port
    }else{
      port <- as.integer(sample(3000:49000, 1))
    }

    x <- callr::r_bg(function(x, y){shiny::runApp(x, port = y)}, args = list(sa , port))
    viewer(paste0("http://localhost:",port,"/"))
    return(invisible(x))
  }

  cat("\nThis is designed for RStudio\n")

  return(invisible(0))

}
runApp_nb(shinyApp(ui = ui, server = server))

@bedantaguru
Copy link
Member Author

See this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Kept for Later This will be implemented in future is required
Projects
None yet
Development

No branches or pull requests

1 participant