Skip to content

Commit e6ed926

Browse files
committed
Add the Shiny app: app.R
1 parent 4472cca commit e6ed926

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

app.R

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Based on SO Question:
2+
# https://stackoverflow.com/questions/78153629/static-version-of-r-shiny-app-using-shinylive-package-failing-to-preload-package
3+
4+
# Load required libraries
5+
library(shiny)
6+
library(shinythemes)
7+
8+
# Define UI
9+
ui <- fluidPage(
10+
theme = shinytheme("flatly"),
11+
12+
# App title
13+
titlePanel("CSV File Uploader"),
14+
15+
# Sidebar layout with input and output definitions
16+
sidebarLayout(
17+
sidebarPanel(
18+
fileInput("file", "Choose CSV File", accept = ".csv"),
19+
tags$hr(),
20+
checkboxInput("header", "Header", TRUE),
21+
checkboxInput("stringAsFactors", "Convert strings to factors", TRUE)
22+
),
23+
24+
# Show CSV data
25+
mainPanel(
26+
tableOutput("contents")
27+
)
28+
)
29+
)
30+
31+
# Define server logic
32+
server <- function(input, output) {
33+
34+
# Read CSV file
35+
data <- reactive({
36+
req(input$file)
37+
df <- read.csv(input$file$datapath,
38+
header = input$header,
39+
stringsAsFactors = input$stringAsFactors)
40+
return(df)
41+
})
42+
43+
# Show CSV data
44+
output$contents <- renderTable({
45+
data()
46+
})
47+
}
48+
49+
# Run the application
50+
shinyApp(ui = ui, server = server)

0 commit comments

Comments
 (0)