【问题标题】:Setting xlim for rbokeh plot inside shiny application在闪亮的应用程序中为 rbokeh 图设置 xlim
【发布时间】:2015-10-03 02:56:51
【问题描述】:

我正在使用rbokeh package for R。在集成到闪亮的应用程序中时,我取得了一些不错的效果。我现在想集成一个功能,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()

以上是示例数据,但它在没有 rbokeh::figure 中的 xlim 参数的情况下也能工作,因为在输入子集中输入从 1 到 4 的数字会相应地对数据进行分组,并产生反应式绘图。 xlim 参数似乎在情节中产生错误。谁能指出我尝试解决 xlim 问题的正确方向?

如果您需要更多详细信息,请告诉我。

【问题讨论】:

  • 'xlim` 通常需要一个长度为 2 的向量来标识范围的起点和终点。那么,不妨试试'xlim=c(min(input$date_range), max(input$date_range))
  • 嗨 ulfeder,inpute$date_range 返回一个长度为 2 的向量
  • 啊,好的。然后我不确定问题是什么;这是我最好的猜测。

标签: r shiny bokeh rbokeh


【解决方案1】:

这似乎是 rbokeh 中的日期格式问题:https://github.com/bokeh/rbokeh/issues/100,应该很快就会修复。

【讨论】:

    猜你喜欢
    • 2018-12-11
    • 2013-07-08
    • 2017-01-27
    • 1970-01-01
    • 2014-03-26
    • 2021-05-01
    • 2016-12-20
    • 2018-11-09
    • 1970-01-01
    相关资源
    最近更新 更多