...i am uploading a csv file and trying to plot a scatter based on user input values. but on clicking plot a blank whte box pops up. can't understand if the issue is with ggplot command or with accessing the user input.
also a code has been written to create matrix by user input but does not how to access this data. we would like to plot a scatterplot based on these matrix too.
ps: sorry for the huge chunk of code but since i didn't know where the error seems to be happening i have put it all
library(shiny)
library(ggplot2)
ui <- fluidPage(
titlePanel(" REGRESSION "),
sidebarLayout(
sidebarPanel(
h4("DEFINITION ")
),
mainPanel(
column(9, navbarPage(title = "REGRESSION MENU ",
navbarMenu("DATA INPUT",
tabPanel("IMPORT FILE",fileInput("file", h3("File input"))),
tabPanel("VIEW DATA", tableOutput("table1")),
tabPanel("INPUT DATA",uiOutput("lot_of_input"),tableOutput("value"),uiOutput("textoutput")),
tabPanel("SUMMARY", verbatimTextOutput("summ"))),
navbarMenu(" LINEAR REGRESSION ",
tabPanel("SELECT DATA",uiOutput("selectbox1"),uiOutput("selectbox11")),
tabPanel("PLOT",uiOutput("plot1")))))
)
)
)
server <- function(input, output) {
#read file
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file=file1$datapath,sep=",")
})
#print file in the view tab
output$table1 <- renderTable({
if(is.null(data())){return ()}
data()
})
output$plot1<-renderUI({
obj<-data.frame(input$select_dev1,input$select_dev11)
plotOutput("p")
})
output$p <- renderPlot({
plot1.obj<-data()
p<-ggplot(plot1.obj)+
aes(geom_point(
x = plot1.obj$select_dev1,
y = plot1.obj$select_dev11
))
})
#summary of file
output$summ <- renderPrint({
if(is.null(input$file)){return()}
summary(read.table(file=input$file$datapath,
sep=",",header=TRUE))})
#matrix input option in input data tab
output$lot_of_input <- renderUI({
x <- list(
numericInput(inputId = "nrow",label = "number of rows",min = 1,max = 20,value = 1),
numericInput(inputId = "ncol",label = "number of columns",min = 1,max = 20,value = 1))
fluidRow(
lapply(
X = split(x, f = rep(c(1, 2), length.out = length(x))),
FUN = column, width = 6
)
)
})
#selectbox dependent option in LR
output$selectbox1 <- renderUI({
selectInput(inputId = "select_dev1",
label = "Select dependent variable",
choices = names(data()))
})
#selectbox independent option in LR
output$selectbox11 <- renderUI({
selectInput(inputId = "select_dev11",
label = "Select independent variable",
choices = names(data()))
})
#matrix diplay option in tab
isolate({
output$value <-renderTable({
num.inputs.col1 <- paste0("<input id='r", 1:input$nrow, "c", 1, "' class='shiny-bound-input' type='number' value='1'>")
df <- data.frame(num.inputs.col1)
if (input$ncol >= 2){
for (i in 2:input$ncol){
num.inputs.coli <- paste0("<input id='r", 1:input$nrow, "c", i, "' class='shiny-bound-input' type='number' value='1'>")
df <- cbind(df,num.inputs.coli)
}
}
colnames(df) <- paste0(" variable ",as.numeric(1:input$ncol))
df
}, sanitize.text.function = function(x) {x})
})
output$textoutput <- renderUI(paste0("Cells [1,1] and [2,2]: ",input$r1c1,",",input$r2c2))
}
shinyApp(ui = ui, server = server)