gpt4 book ai didi

r - 在 Shiny 的应用程序中为 rbokeh 图设置 xlim

转载 作者:行者123 更新时间:2023-12-04 11:45:09 24 4
gpt4 key购买 nike

我正在使用 rbokeh package for R .我在集成到一个 Shiny 的应用程序中取得了一些不错的结果。我现在想集成一个功能,其中一个 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 问题的正确方向吗?

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

最佳答案

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

关于r - 在 Shiny 的应用程序中为 rbokeh 图设置 xlim,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31407177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com