Reputation: 41
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,
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"))))
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)
Upvotes: 1
Views: 5090
Reputation: 161
It appears that you are new to Shiny, so I wrote the working example for you so you can study on.
I also created the dummy dataset per your description and stack them together into one data.frame.
for plotting time series, and any other types of charts, please look into ggplot2. for subsetting series by some variables, you'll need dplyr. Both created by RStudio Team.
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)
Upvotes: 4