简体   繁体   English

在闪亮的应用程序中设置xlim for rbokeh plot

[英]Setting xlim for rbokeh plot inside shiny application

I'm using the rbokeh package for R . 我正在使用r的rbokeh包 I've been having some good results integrating into a shiny app. 我已经将一些好的结果整合到一个闪亮的应用程序中。 I want to now integrate a feature where a dateRangeInput will now select the date range for the chart(it is time series data). 我现在要集成一个功能,其中dateRangeInput现在将选择图表的日期范围(它是时间序列数据)。

##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 is example data but it works without the xlim argument in rbokeh::figure, as in that typing in a number from 1 to 4 in the input subsets the data accordingly and produces a plot reactively. 以上是示例数据,但它在rbokeh :: figure中没有xlim参数的情况下工作,因为在输入子集中键入1到4的数字相应的数据并反复生成一个图。 The xlim argument seems to produce errors in the plot. xlim参数似乎在图中产生错误。 Could anyone perhaps point me in the right direction in trying to fix the xlim issue? 任何人都可以指出我正在努力解决xlim问题吗?

Let me know if you need any more details. 如果您需要更多详细信息,请与我们联系。

它似乎是rbokeh中的日期格式问题: https//github.com/bokeh/rbokeh/issues/100应尽快修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM