Я хочу рисовать активный график (Live Continues) динамически, когда я просматриваю файл CSV.И от этого пользователя выберет два значения (X и Y) из selectInput.По выбору пользователя активный график должен генерироваться динамически.
Я пытаюсь с раннего утра.Если я помещу график в бесконечный цикл while, он не отобразится.Но я не понимаю, что делать.Если кто-нибудь сможет мне помочь, это будет очень полезно для меня.Здесь я прилагаю два моих файла, т.е. UI.R и SERVER.R
ui.r
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
fileInput('datafile', 'Choose CSV file',accept=c('text/csv', 'text/comma-
separated-values,text/plain')),
numericInput("obs", "Enter the number of rows to display:", 5),
selectInput("sep", "Seperator", choices = c(Comma = ',', semicolon = ';',
tab = "\t", space = " " ))
),
mainPanel(
tabsetPanel( id = "tabs",
tabPanel("Display File", tableOutput("input_file")),
tabPanel("Generate Plot",dashboardSidebar(h4("Select columns from CSV to plot"),
uiOutput("selectX"),uiOutput("selectY"),
radioButtons("type","Select File Type:", choices = list("png","pdf")),
selectInput(inputId = "plot",
label = "Select Plot:",
choices = c("BoxPlot","BarPlot","Simple Plot","Plot with Density"),
selected = "BoxPlot"),
colourInput("color", "Select colour", value = "blue")),
plotOutput("plot")))
)
)
)
)
server.r
library(shiny)
shinyServer(function(input, output) {
#This function is repsonsible for reading a csv file
file <- reactive({
req(input$datafile)
infile <- input$datafile
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
read.csv(infile$datapath,nrows = input$obs, sep = input$sep)
})
#This function is repsonsible for reading numeric fields from csv file
filedata <- reactive({
req(input$datafile)
infile <- input$datafile
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
file<-read.csv(infile$datapath,nrows = input$obs, sep = input$sep)
nums <- unlist(lapply(file, is.numeric))
file[,nums]
})
output$input_file <- renderTable({
file()
})
#This function responsible to Select the X value while drawing the plot.
output$selectX <- renderUI({
df <- filedata()
if (is.null(df)) return(NULL)
items=names(df)
names(items)=items
selectInput("x", "Select X-axis:",items)
})
#This function responsible to Select the Y value while drawing the plot.
output$selectY <- renderUI({
df <- filedata()
if (is.null(df)) return(NULL)
items=names(df)
names(items)=items
selectInput("y", "Select Y-axis:",items)
})
#This function is responsible for drawing the plots
output$plot <- renderPlot({
cont <- TRUE
req(input$x)
req(input$y)
df <- filedata()
while(cont == TRUE){
if(input$plot == "BoxPlot"){
boxplot(df[,input$x],df[,input$y],col = input$color,xlab = input$x, ylab = input$y, main = "Complete Blood Count Data" )
}
else if(input$plot == "BarPlot")
{
barplot(df[,input$x],df[,input$y],col = input$color,xlab = input$x, ylab = input$y, main = "Complete Blood Count Data")
}
else if(input$plot == "Simple Plot"){
plot(df[,input$x],df[,input$y],col = input$color,xlab = input$x, ylab = input$y, main = "Complete Blood Count Data")
}
else if(input$plot == "Plot with Density"){
plot(density(df[,input$x],df[,input$y]),col = input$color,xlab = input$x, ylab = input$y, main = "Complete Blood Count Data")
}
}
})
})