首页 > 解决方案 > 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)

标签: rshinyshinydashboardshinyapps

解决方案


这是一个非常基本的例子

您应该在“服务器”功能中进行“思考”。

希望这个示例将向您展示反应式输入和输出如何相互关联,并且您可以将其扩展到您的绘图中。

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 做一些事情来制作你的情节。


推荐阅读