My app (uploaded to shiny apps.io) when downloading creates a -2.csv copy instead of overwriting the same-name previously created file. It is important I be able to keep the same name and overwrite the prior file.
To explore the problem I adapted the Shiny Help example I found online named "10_download" to my situation. I tested it with both R's data frame 'rock' and my data frame 'problem_df'. I wrote .csv files for both of these data frames and put them into my download folder.
The app does overwrite correctly into my download folder using 'rock'. It creates the -2 copy when using 'problem_df'; additionally, problem_df-2.csv has 4 extra bytes that problem_df.csv did not have. Additionally, I can then overwrite problem_df-2.csv just fine.
What is wrong with problem_df.csv that it does not get overwritten?
Here is my data:
"user","height","entry_date","hr_slept","min_exer","min_str","ate_med_mind","ate_processed","ate_fast","ate_sugar","ate_alcohol","mng_stress","social_contact","challenge_cog","new_learn","learn_what","weight","blood_sugar","systolic","diastolic","not_smoker","normal_hearing","not_depressed"
"f",69,2019-09-04,6,0,30,1,1,0,1,0,1,1,1,1,"Sql plus",0,0,0,0,0,0,0
"f",69,2019-09-03,5,30,0,0,0,0,0,0,0,0,0,0,"",0,0,0,0,0,0,0
I already have the code uploaded to shiny apps.io and here is the url:
https://cut-risk.shinyapps.io/adapted_10_download/
Here is the code:
library(shiny)
ui <- fluidPage(
# App title ----
titlePanel("Downloading Data"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Choose dataset ----
fileInput("fileIn", label = h3("Choose the file to read in (i.e. 'rock' or 'problem_df')")),
# Button
downloadButton("downloadData", "Download")
),
# Main panel for displaying outputs ----
mainPanel(
tableOutput("table")
)
)
)
server <- function(input, output) {
# Reactive value for selected dataset ----
datasetInput <- reactive({
filename_selected = input$fileIn
datIn = read.csv(filename_selected$datapath,stringsAsFactors = FALSE)
datasetInput = list(datIn,filename_selected$name)
})
# Table of selected dataset ----
output$table <- renderTable({
filename_selected = input$fileIn
validate(
need(input$fileIn, " ")
)
datasetInput()[[1]]
})
# Downloadable csv of selected dataset ----
output$downloadData <- downloadHandler(
filename = function() {
datasetInput()[[2]]
},
content = function(file) {
write.csv(datasetInput()[[1]], file, row.names = FALSE)
}
)
}
shinyApp(ui, server)
Thank you for any help!