I am trying to create a Shiny app where a user can upload a csv file, input a numeric value, add the numeric value to a specific column of data in the csv, then save the raw + calculated data in a table. I generated a simplified Shiny script below using a simple csv file.
When I try and run the app, I get the error:
Problem with mutate()
input sum
.
[31mx[39m non-numeric argument to binary operator
[34mi[39m Input sum
is A + C
.
I tried looking up some examples of how to fix this, but was unable to find something that utilized eventReactive() to keep the data table updated with the new calculated data. Any help is greatly appreciated.
library(shiny) library(dplyr)
ui <- fluidPage(
# Application title
titlePanel("Test"),
# Show a plot of the generated distribution
mainPanel(
fileInput(
inputId = "csvFile",
label = "Upload csv file",
accept = c(".csv")),
uiOutput("C"),
uiOutput("D"),
tableOutput("modifiedData")
)
)
server <- function(input, output) {
output$C <- renderUI(
{numericInput("C", "Variable C", 0)}
)
output$D <- renderUI(
{numericInput("D", "Variable D", 0)}
)
userData <- eventReactive(input$csvFile,
{
req(input$csvFile)
raw_df <- read.csv(input$csvFile$datapath)
calc_df <- raw_df %>%
mutate(sum = A + C)
})
output$modifiedData <- renderTable({userData()})
}
shinyApp(ui = ui, server = server)
C
, which is a single numeric value, to all the 6 rows of columnA
? In that case you needmutate(sum = A + input$C)
– YBS