简体   繁体   English

闪亮的应用程序时间序列图与数据框架

[英]Shiny App Time Series plot with data frame

I am trying to build a simply Shiny app, which can take data input from a CSV file and then display the data along with a ts plot, here is the R code that I have written, 我正在尝试构建一个简单的Shiny应用程序,它可以从CSV文件中获取数据,然后显示数据以及ts图,这是我编写的R代码,

ui.R file ui.R文件

library(shiny)
shinyUI <- fluidPage(
  titlePanel(h2("Blood Test Result System",align = "center")),
  sidebarLayout(    
  sidebarPanel(

  selectInput(inputId = "dataset",
                         label = "Choose a blood value:",
                         choices = c("Albumin","Bilirubin","CL(KLOR)","Glukoz","Kalsiyum","Kolesterol",
                                     "Kreatinin","Potasyum","Protein","Trigliserid","Hdl Kolesterol","Kreatin Kinaz"))),
mainPanel(
  verbatimTextOutput("summary"),
  tableOutput("view"))))

server.R file server.R文件

library(shiny)
shinyServer(

  function(input,output){

datasetInput <- reactive({
  switch(input$dataset,
         "Albumin"=albumin,
         "Bilirubin"=biliribun,
         "CL(KLOR)"=clklor,
         "Glukoz"=glukoz,
         "Kalsiyum" = kalsiyum,
         "Kolesterol" = kolesterol,
         "Kreatinin" = kreatinin,
         "Kreatin Kinaz" = kreatinkinaz,
         "Potasyum" = potasyum,
         "Protein" = protein,
         "Trigliserid"=trigliserid,
         "Hdl Kolesterol"=hdlkolesterol,
         "Kreatin Kinaz"=kreatinkinaz)

})


# Generate a summary of the dataset ----
output$summary <- renderPrint({
  dataset <- datasetInput()
  summary(dataset)
})})

How can i implement ps plot with blood test value and their dates?I have 13 blood values as data frame (date,value_name,result,unit, interval) like (2019-01-28,Potassium,4.00,mmol/L,3.5-5.2) 如何用血液测试值和他们的日期实现ps图?我有13个血液值作为数据框(日期,value_name,结果,单位,间隔)像(2019-01-28,钾,4.00,mmol / L,3.5 -5.2)

It appears that you are new to Shiny, so I wrote the working example for you so you can study on. 您似乎是Shiny的新手,所以我为您编写了工作示例,以便您可以继续学习。

I also created the dummy dataset per your description and stack them together into one data.frame. 我还根据您的描述创建了虚拟数据集,并将它们一起堆叠成一个data.frame。

for plotting time series, and any other types of charts, please look into ggplot2 . 如需绘制时间序列和任何其他类型的图表,请查看ggplot2 for subsetting series by some variables, you'll need dplyr . 对于某些变量对子系列进行子集化,您需要dplyr Both created by RStudio Team. 两者都是由RStudio团队创建的。

Welcome to the Shiny world! 欢迎来到闪亮的世界!

library(shiny)
library(dplyr)
library(ggplot2)

potasyum_data <- data.frame(date=seq(as.Date("2019/6/1"), by = "day", length.out = 30),
                          value_name = rep("Potasyum", 30),
                          result=sample(1:100, 30))

protein_data <- data.frame(date=seq(as.Date("2019/6/1"), by = "day", length.out = 30),
                            value_name = rep("Protein", 30),
                            result=sample(1:100, 30))     

stack_data <- rbind(potasyum_data, protein_data)

ui <- fluidPage(
  titlePanel(h2("Blood Test Result System",align = "center")),
  sidebarLayout(    
    sidebarPanel(

      selectInput(inputId = "dataset",
                  label = "Choose a blood value:",
                  choices = c("Potasyum", "Protein"),
                  selected = "Protein")),
    mainPanel(
      plotOutput("ts_plot"),
      verbatimTextOutput("summary"))))

server <- shinyServer(

  function(input,output){

    datasetInput <- reactive({
      stack_data %>% filter(value_name == input$dataset)
    })


    # Generate a summary of the dataset ----
    output$summary <- renderPrint({
      dataset <- datasetInput()
      summary(dataset$result)
    })

    # plot time series
    output$ts_plot <- renderPlot({

      dataset <- datasetInput()
      ggplot(dataset, aes(x = date, y=result)) + geom_line()

    })
  })



shiny::shinyApp(ui = ui, server = server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM