My shiny app requires users to input a file they want to process, but I would also like to provide an option to use the default file for them to try out the dashboard. I've set up a radio button to use that file in my ui.R like so:
checkboxInput("checkbox", label = "Or Use default file", value = FALSE)
In my server.R, I have defined the logic as follows:
# Define server logic to read selected file ----
server <- function(input, output) {
output$myTable <- renderDataTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, head of that data file by default,
# or all rows if selected, will be shown.
if(input$checkbox == FALSE){
req(input$file1)
data <- readr::read_fwf(input$file1$datapath,
fwf_empty(input$file1$datapath),
skip = input$skiplines
)}
else {
data <- readr::read_fwf("https://raw.githubusercontent.com/thedivtagguy/srishtilibrary/main/books_raw.txt", fwf_empty("https://raw.githubusercontent.com/thedivtagguy/srishtilibrary/main/books_raw.txt", col_names = c("Title")),skip = 10
)
}
data <- data %>% rename(Title = X1)
# Code to process the rest of the file follows
return(data)}
}
}
But this does not read the url of the text file and assign it to data when clicked. What am I doing wrong?
Full gist uploaded here: https://gist.github.com/thedivtagguy/74de5ae9d853828530f3414e6b52df95
Aucun commentaire:
Enregistrer un commentaire