Plot 我的第一个闪亮的应用在R时间系列请求

Plot 我的第一个闪亮的应用在R时间系列请求,plot,shiny,time-series,rstudio,Plot,Shiny,Time Series,Rstudio,我有一张这样的桌子: EmpNum Sym Jan_C Feb_C Mar_C 34335333 2200 400 300 200 34334533 2243 300 200 100 2424142 5025 200 100 400 1023231 5021 204 532 2300 我对根据用户的选择绘制时间序列感兴趣。他将选择EmpNum和Sym,输出将是从

我有一张这样的桌子:

    EmpNum      Sym   Jan_C Feb_C Mar_C
    34335333    2200    400 300     200
    34334533    2243    300 200    100
    2424142     5025    200 100     400
    1023231     5021    204 532    2300
我对根据用户的选择绘制时间序列感兴趣。他将选择EmpNum和Sym,输出将是从1月到3月的系列图。我开始写这篇文章:

    **ui.R**

    shinyUI(
 pageWithSidebar (
   headerPanel ("My Shiny App"), 

sidebarPanel (
 selectInput("Employee", "Please Select An Employee Number:",
              choices=data$EmpNum,2424142),
 selectInput ("Symbol", "Please Select Salary Symbol:",
                           choices=data$Sym, 5025)
),
mainPanel(plotOutput("myPlot"))

)
)
以及:

**server.r:**
shinyServer(
功能(输入、输出、会话){

输出$myPlot这是一个使用动态输入的解决方案。我模拟了数据,因为您没有提供可复制的问题:

server.R

# create mock data
set.seed(1)
data <- data.frame(EmpNum = rep(seq(500), each = 5), Sym = rep(c("A", "B", "C", "D", "E"), 500), dp1 = runif(500), dp2 = runif(500), dp3 = runif(500))

# remove some columns to test reactive selection
n <- nrow(data)
droprows <- sample(seq(n), floor(n*0.7))
data <- data[-droprows, ]

shinyServer (
  function (input,output,session){

    output$employee <- renderUI({
      selectInput("Employee", "Please Select An Employee Number:",
                  choices = sort(data$EmpNum))
    })

    output$symbol <- renderUI({
      if (!is.null(input$Employee)){
        selectInput ("Symbol", "Please Select Salary Symbol:",
                    choices = sort(unique(data[data$EmpNum == input$Employee, ]$Sym)))  
      }
    })


    output$myPlot <- renderPlot({
      if (all(!is.null(input$Employee), !is.null(input$Symbol))){

      seData  <- as.numeric(data[data$EmpNum == input$Employee & data$Sym == as.character(input$Symbol),][3:5])
      Et  <- ts(seData, start=1,end=3)
      plot(Et,col="blue")
      }
    })
  })
shinyUI(
  pageWithSidebar (
    headerPanel ("My Shiny App"), 

    sidebarPanel (
      uiOutput("employee"),
      uiOutput("symbol")
    ),
    mainPanel(plotOutput("myPlot"))

  )
)
shinyUI(
  pageWithSidebar (
    headerPanel ("My Shiny App"), 

    sidebarPanel (
      uiOutput("employee"),
      uiOutput("symbol")
    ),
    mainPanel(plotOutput("myPlot"))

  )
)