In my application, I ask the user to input a file (.csv). Further there are two selectInput(s) which are populated with column names from the input file using renderUI(). As user selects two different columns and click submitButton a plot is generated. The UI with ideal output is given below. This works because i have manually input the values in plot and it does not take the columns as selected in drop down options.
correct output
I think the problem is converting factor type elements in dataframe to numeric type which can be plotted.
the error image :
server.R
library(shiny)
shinyServer(function(input, output) {
lastgang <- reactive({
if(is.null(input$file)){return()}
read.table(file=input$file$datapath, header =TRUE, sep=",")
})
output$X = renderUI({
selectInput("X", "Select field to plot along X axis", names(lastgang()), selected = NULL)
})
output$Y = renderUI({
selectInput("Y", "Select field to plot along Y axis", names(lastgang()), selected = NULL)
})
output$plot <- renderPlot({
if (is.null(input$X) || is.null(input$Y)){return()}
x = input$X
y = input$Y
plot(as.numeric(lastgang()$x),as.numeric(lastgang()$y))
})
})
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("Source Design"),
sidebarLayout(
sidebarPanel(fileInput("file", label = h4("Select *.csv file")),
uiOutput("X"),
uiOutput("Y"),
submitButton("Plot")
),
mainPanel(
plotOutput('plot') )
)
))


as.numericprobably produces a vector which only consists ofNAentries. What kind of data do you have? Edit: I saw you callx <- input$Xand afterwards you are callinglastgang()$x. That ought to be onlyx, or not? Otherwise the assignmentx <- input$Xmakes no sense I think. Unfortunately I have no experience withshiny... - FlorianSchunkex = input$Xwill return a column/element name. To get the series of values under that column i am calling lastgang()$x where lastgang() is bascially a R dataframe converted from .csv file. Further i checked that both columns that i have selected are of typenum. - Jio