library(shiny)
library(shinythemes)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Cargar el conjunto de datos
HousePriceData <- read.csv("HousePriceData.csv")
ui <- fluidPage(theme = shinytheme("spacelab"),
navbarPage("APPS",
tabPanel("Precio inmueble"),
sidebarPanel(
tags$h5("Ingresa las especificaciones sobre las características de hogar soñado:"),
sliderInput("Dist_Taxi", "Selecciona la distancia a la que te gustaría tener un taxi en mts:", 0, 17000, 8500),
sliderInput("Dist_Hospital", "Selecciona la distancia a la que te gustaría tener un hospital en mts:", min=0, max=25000, value=12500),
sliderInput("Carpet", "Selecciona los m2 que te gustaría en tu piso:", min=0, max=25000, value=12500),
sliderInput("Builtup", "Cuantos m2 te gustaría que fuera tu construcción?", min=0, max=15000, value=7500),
selectInput("Parking", "Te gustaría tener estacionamiento?:", choices = c("Open", "Not Provided", "Covered", "No Parking")),
selectInput("City_Category", "En qué categoría de ciudad te gustaría vivir?:", choices = c("CAT A", "CAT B", "CAT C")),
sliderInput("Rainfall", "Qué tanta precipitación te gustaría en el área donde vivas?:", min=-200, max=2000, value=900)
),
mainPanel(
h1("Esto costaría tu casa soñada:"),
verbatimTextOutput("valor")
)
)
)
## Warning: Navigation containers expect a collection of
## `bslib::nav_panel()`/`shiny::tabPanel()`s and/or
## `bslib::nav_menu()`/`shiny::navbarMenu()`s. Consider using `header` or `footer`
## if you wish to place content above (or below) every panel's contents.
## Warning: Navigation containers expect a collection of
## `bslib::nav_panel()`/`shiny::tabPanel()`s and/or
## `bslib::nav_menu()`/`shiny::navbarMenu()`s. Consider using `header` or `footer`
## if you wish to place content above (or below) every panel's contents.
server <- function(input, output) {
output$valor <- renderPrint({
# Crear un nuevo conjunto de datos con los valores ingresados por el usuario
new_data <- data.frame(
Dist_Taxi = input$Dist_Taxi,
Dist_Hospital = input$Dist_Hospital,
Carpet = input$Carpet,
Builtup = input$Builtup,
Parking = input$Parking,
City_Category = input$City_Category,
Rainfall = input$Rainfall
)
# Realizar la predicción utilizando el modelo de regresión previamente entrenado
regresion <- lm(House_Price ~ Dist_Taxi + Dist_Hospital + Carpet + Builtup + Parking + City_Category + Rainfall, data = HousePriceData)
predicted_price <- predict(regresion, newdata = new_data)
return(predicted_price)
})
}
shinyApp(ui = ui, server = server)
## PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.
Shiny applications not supported in static R Markdown documents