if i save shapefile.zip to my computer, then using the fileinput in the app I can browse to and choose it, and it imports succesfully.
library(shiny)
library(ggplot2)
library(readxl)
library(shinythemes)
library(rdist)
library(geosphere)
library(rgdal)
function.cl<-function(path_to_readOGR,k){
shape<-readOGR(dsn=path_to_readOGR)
df<-shape@data
#clusters
coordinates<-df[c("Latitude","Longitude")]
d<-as.dist(distm(coordinates[,2:1]))
fit.average<-hclust(d,method="average")
clusters<-cutree(fit.average, k)
nclusters<-matrix(table(clusters))
df$cluster <- clusters
#all cluster data df1 and specific cluster df_spec_clust
df1<-df[c("Latitude","Longitude")]
df1$cluster<-as.factor(clusters)
#Colors
my_colors <- rainbow(length(df1$cluster))
names(my_colors) <- df1$cluster
#Scatter Plot for all clusters
g <- ggplot(data = df1, aes(x=Longitude, y=Latitude, color=cluster)) +
geom_point(aes(x=Longitude, y=Latitude), size = 4) +
scale_color_manual("Legend", values = my_colors)
plotGD <- g
return(list(
"Plot" = plotGD
))
}
ui <- bootstrapPage(
navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
"Cl",
tabPanel("Solution",
fileInput("shp",
h3("Shapefile Zip Import"),
multiple = FALSE,
accept = c('.zip')),
sidebarLayout(
sidebarPanel(
sliderInput("Slider", h5(""),
min = 2, max = 4, value = 3),
),
mainPanel(
tabsetPanel(
tabPanel("Solution", plotOutput("ScatterPlot"))))
))))
server <- function(input, output, session) {
Modelcl <- reactive({
req(input$shp)
mytempdir <- tempdir()
unzip(input$shp$datapath, exdir = mytempdir)
shape_path <- dir(path = mytempdir, pattern = ".shp$")
function.cl(
path_to_readOGR = file.path(
mytempdir,
shape_path
),
k = input$Slider
)
})
output$ScatterPlot <- renderPlot({
Modelcl()[[1]]
})
}
shinyApp(ui = ui, server = server)