this app let's you upload a csv file, and it automatically generates lines, area and horizontal bar charts based on your data
Drop files here
or click to upload
library(jsonlite)
library(shiny)
library(ggplot2)
ui <- fluidPage(
titlePanel("CSV Chart Generator"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File", accept = ".csv"),
checkboxInput("header", "Header", TRUE)
),
mainPanel(
tabsetPanel(
tabPanel("Line Chart", plotOutput("linePlot")),
tabPanel("Area Chart", plotOutput("areaPlot")),
tabPanel("Horizontal Bar Chart", plotOutput("barPlot"))
)
)
)
)
server <- function(input, output) {
data <- reactive({
req(input$file1)
validate(need(tools::file_ext(input$file1$datapath) == "csv", "Please upload a csv file"))
read.csv(input$file1$datapath, header = input$header)
})
output$linePlot <- renderPlot({
df <- data()
ggplot(df, aes(x = 1:nrow(df), y = df[[1]])) + geom_line() + labs(title = "Line Chart", x = "Index", y = names(df)[1])
})
output$areaPlot <- renderPlot({
df <- data()
ggplot(df, aes(x = 1:nrow(df), y = df[[1]])) + geom_area(fill = "blue", alpha = 0.5) + labs(title = "Area Chart", x = "Index", y = names(df)[1])
})
output$barPlot <- renderPlot({
df <- data()
ggplot(df, aes(x = reorder(names(df)[1], df[[1]]), y = df[[1]])) + geom_bar(stat = "identity", fill = "lightblue") + coord_flip() + labs(title = "Horizontal Bar Chart", x = names(df)[1], y = "Values")
})
}
shinyApp(ui, server)
Hi! I can help you with any questions about Shiny and R. What would you like to know?