r - how to design a reactive visualization graph for a time series using shiny?
问题描述
I want to design a reactive interaction graph for a time series for shiny.
It is used for when I have a time series. I change the first point of the time series.
Then I can get the reactive graph changed for the point changed.
I have trouble for how to assign the value input into the function. Specifically, for the
yinput<-sensi(num). I want to the input be some number range from 0.1 to 0.9.but my sensitive's
function only allow to enter one input.
Is there any idea for that?
Thanks
library(ggplot2)
sensi<-function(input)
{
y<-c(input,5,12,21,30,50,90,100)
return(y)
}
Date = c("2020/07/16","2020/07/23","2020/07/30","2020/08/06","2020/08/13","2020/08/20","2020/08/27","2020/09/13")
num<-c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9)
yinput<-sensi(num)
df <- data.frame(yinput, Date = as.Date(Date))
ui <- fluidPage(
titlePanel(title=h4("plot1", align="center")),
sidebarPanel(
sliderInput("num", "Number:",min = 0, max = 0.9,value=0.5)),
mainPanel(plotOutput("plot2")))
server <- function(input,output){
dat <- reactive({
test <- df[df$num %in% seq(from=min(input$num),to=max(input$num),by=1),]
print(test)
test
})
output$plot2<-renderPlot({
ggplot(df) + aes(Date, y) + geom_line()})}
shinyApp(ui, server)
解决方案
这是一个非常基本的例子
您应该在“服务器”功能中进行“思考”。
希望这个示例将向您展示反应式输入和输出如何相互关联,并且您可以将其扩展到您的绘图中。
require(shiny)
ui <- fluidPage(
sliderInput("num", "Number:", min = 0.1, max = 0.9, value = 0.5),
textOutput("number_display")
)
server <- function(input, output){
output$number_display <-
renderText({
as.character(input$num)
})
}
shinyApp(ui = ui, server = server)
在我说过的地方as.character(input$num)
,你会想用 num 做一些事情来制作你的情节。
推荐阅读
- visual-studio-2015 - 如何通过变量更改连接管理器中的服务器名称
- nginx - 在 nginx 中创建代理
- javascript - CSS 转换迫使 Safari 重新加载页面
- python - Python 脚本不会像应有的那样将 SQL 查询的结果写入平面 JSON 文件
- spring - 如果数据库表中有很多数据,findAll 方法会影响我的批次吗
- c# - .net clr 内部错误 80131506
- wpf - WPF ToggleButton,按钮样式
- python - 具有分水岭的图像分割:过度分割和合并连接区域
- python - reticulate 包 - 更改 python 版本
- java - 获取 bean 后对象为空