library(shiny)
library(shinydashboard)
library(shiny)
#library(leaflet)
#library(leaflet.extras)
header <- dashboardHeader(
dropdownMenu(
type = "messages",
messageItem(
from = "Data",
message = "Learn how to do your Shiny App",
href = "https://rstudio.github.io/shinydashboard/structure.html#sidebar-menu-items-and-tabs"
)
)
)
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets",
badgeLabel = "new", badgeColor = "green"),
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",".csv")),
sliderInput("bins",
"Number of bins:",
min = 1,
max = 10000,
value = 500),
sliderInput("opacity", "Opacity:",
min = 0, max = 1,
value = 0.5, step = 0.1)
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "dashboard",
h2("Dashboard tab content")
),
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
),
mainPanel(
plotOutput("distPlot")
) #main panel
) #body
ui <- dashboardPage(header, sidebar, body)
# Define server logic required to draw a histogram
server <- function(input, output) {
mydataset <- reactive({
print("started mydata <- reactive")
inputfile1 <- input$file1
if (is.null(inputfile1)) return(NULL)
df1 = data.frame(read.csv(inputfile1$datapath, as.is=TRUE))
#VALIDATE DATA
print("ended mydata <- reactive")
return(df1)
})
observeEvent(input$file1, {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- mydataset[,2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
}) # renderPlot
}) #observeEvent
}#server
# Run the application
shinyApp(ui = ui, server = server)