Last active
February 12, 2021 08:36
-
-
Save thedivtagguy/7e5bf127dffa447bcb6dc01526183b3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
ui <- fluidPage( | |
titlePanel("Srishti Library Database"), | |
# Sidebar layout with input and output definitions ---- | |
# Sidebar panel for inputs ---- | |
sidebarPanel( | |
# Input: Select a file ---- | |
fileInput("file1", "Choose Library File", | |
multiple = TRUE, | |
accept = c("text/csv", | |
"text/comma-separated-values,text/plain", | |
".csv")), | |
# Copy the line below to make a checkbox | |
checkboxInput("checkbox", label = "Or Use default file", value = FALSE), | |
# Horizontal line ---- | |
tags$hr(), | |
numericInput("skiplines", "Number of Lines to Skip:", 10, min = 1, max = 100), | |
# Horizontal line ---- | |
tags$hr(), | |
), | |
# Main panel for displaying outputs ---- | |
mainPanel( | |
# Output: Data file ---- | |
dataTableOutput('myTable') | |
) | |
) | |
# 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), | |
return(data) | |
}, options = list( extensions = 'Buttons', buttons = | |
list("copy", list( | |
extend = "collection" | |
, buttons = c("csv", "excel", "pdf") | |
, text = "Download")),pageLength = 10, info = FALSE, searchHighlight = TRUE)) | |
} | |
# Run the app ---- | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment