Xlim setting for rbokeh graphics inside a brilliant app

I use the package for the R rbokeh . I had good results integrating into a brilliant app. I now want to integrate a function in which dateRangeInput will now select a date range for the graph (this is time series data).

##necessary packages

install.packages("shiny")
install.packages("devtools")
install.packages("dplyr")
library(devtools)
devtools::install_github("ramnathv/htmlwidgets")
devtools::install_github("bokeh/rbokeh")
library(rbokeh)
library(dplyr)
library(shiny)

#example data set

james<-mtcars[c("mpg")]
james$date<-seq(from=as.Date("2013-05-16"),to=as.Date("2013-06-16"),by="days")
james$index<-1:4

#shiny app

shiny_example <- function(chart_data = james){

  date_minmax <- range(chart_data$date)

  shinyApp(
    ui=fluidPage(
      titlePanel("a plot"),
      sidebarLayout(
        sidebarPanel(
          textInput("index","Enter the index from 1 to 16",value=1),
          uiOutput("date_range")
        ),
        mainPanel(
          rbokeh::rbokehOutput("plot_cars")
        )
      )
    ),
    server=function(input,output,session)
    {
      current_data <- reactive({
        current_df <- subset(james,index==input$index)
        return(current_df)
      })
      output$date_range <- renderUI({
        plot_data <- current_data()
        current_id_range <- range(plot_data$date)
        return(
          dateRangeInput("date_range",
                         "Date Range(X Axis",
                         min=date_minmax[1],
                         max=date_minmax[2],
                         start=current_id_range[1],
                         end=current_id_range[2])
        )
      })
      output$plot_cars <- rbokeh::renderRbokeh({
        plot_data <- current_data()
        g<-rbokeh::figure(title="Cars",
                          width=800,
                          heigh=400,
                          xlab="Date",
                          ylab="mpg",
                          xlim=input$date_range) %>%
          rbokeh::ly_points(date,
                            mpg,
                            data=plot_data) %>%
          rbokeh::ly_lines(date,
                           mpg,
                           data=plot_data,
                           alpha=0.3)
        return(g)
      })
    }

  )
}
##run the app

shiny_example()

The above examples are examples, but they work without the xlim argument in rbokeh :: figure, as in that they enter a number from 1 to 4 in the input data subsets, respectively, and produce a graph reactively. The xlim argument seems to cause plot errors. Can someone possibly point me in the right direction while trying to fix the xlim problem?

Let me know if you need more details.

+4
1
0

All Articles