I am doing some mathematical calculations and depending on the user's answer the numeric variables inside an output table changes. however the table is fixed and does not change value when the user input values change.
please help.
Q1. how to get my output table interactive with the input numbers?
Q2. how to create output table in (T2) it is giving me error and I couldnt solve the problem
here is the code I developed
library(shiny)
library(shiny.i18n)
library(shinyWidgets)
library(shinydashboard)
library(DT)
library(scales)
library(leaflet)
library(spData)
library(dplyr)
library(sp)
library(maps)
library(rsconnect)
library(htmltools)
library(rgdal)
library(geojson)
library(geojsonio)
library(geojsonR)
library(rbison)
library(devtools)
library(raster)
library(readxl)
library(quantmod)
library(rmarkdown)
library(tidyxl)
library(tidyverse)
library(rlang)
library(rdrop2)
library(zoo)
library(devtools)
library(quantmod)
library(xts)
library(reprex)
library(openxlsx)
library(rhandsontable) #dynamic tables with simulating funcitons
library(tidyr)
library(purrr)
library(ggplot2)
library(lexl) # separates Excel formula into tokens of different types, its called "bad pun" on Excel
library(ggraph)
library(unpivotr)
library(readr)
ProjectWD <- "C:/Users/Contil dell/Documents/Project1" # project Directory saved location
setwd (ProjectWD)
####################################calculations###############################
mod1 = function(Q1,Q2,Q3,Q4,Q5,Q6){
A1= 52995.30
A2= 2.14
A3= 84.60
A4= 84.99
A5= 134.80
A6= 173.96
A7= 197.77
A8= 0
A9= 14.48
A10= 17.27
A11= 17.71
A12= 21.88
A13= 22.41
A14= 0
A15= 150
A16= 72
A17= 404
A18= 92
A19= 50
A20= 0
A21= 2092.48
A22= 2092.48
A23= 146
A24= 292.20
A25= 1.00
A26= 29480000
A27= 28760000
A28= 26210000
A29= 21520000
A30= 20210000
A31= 0
#?????泳?怨??렭?????졂 ???獒???????븪?쓹夷???
B1= 0.15
B2= 0.4
B3= 0.3
B4= 1.5
B5= 36
B6= 33
B7= 5700000
B8= 5500000
B9= 5300000
B10= 700000
B11= 3.5
B12= 0.05
B13= 1
B14= 0.15
B15= 0.06
#????젂?遊븀빊????꼯????????졂???뀇?? ??뇦猿곴뮈鴉???泳???筌??
BA1= A3A15+A4A16+A5A17+A6A18+A7A19+A8A20
BA2= A9A15+A10A16+A11A17+A12A18+A13A19+A14A20
BA3= A1*A2
BA4= BA1+BA2
BA5= BA4+A21+A23-BA3
BA7= if(BA5<0) 0 else BA5
BA6= BA2-BA7
#Number of housesholds
NH1 = A15+A16+A17+A18+A19+A20
NH2= floor(NH1* B1)
NH3= floor(NH1+NH2)
NH5= floor(A16Q6)
NH6= floor(A17Q6)
NH7= floor(A18Q6)
NH8= floor(A19Q6)
NH9= floor(A20Q6)
NH10= floor(NH1Q6)
NH4= NH10-NH9-NH8-NH7-NH6-NH5
NH11= NH2+NH10
NH12= A15-NH4
NH13= A16-NH5
NH14= A17-NH6
NH15= A18-NH7
NH16= A19-NH8
NH17= A20-NH9
NH18= NH12+NH13+NH14+NH15+NH16+NH17
#(???땻???琉?????留?) ???쐪???뮝???빂?筌???????踰????獒뺣톪?뵾??뒧??떔??源????諭?
AF1= if(A3<85) A3*(1+B2) else A3*(1+B3)
AF2= if(A4<85) A4*(1+B2) else A4*(1+B3)
AF3= if(A5<85) A5*(1+B2) else A5*(1+B3)
AF4= if(A6<85) A6*(1+B2) else A6*(1+B3)
AF5= if(A7<85) A7*(1+B2) else A7*(1+B3)
AF6= if(A8<85) A8*(1+B2) else A8*(1+B3)
AF7= AF1-A3
AF8= AF2-A4
AF9= AF3-A5
AF10= AF4-A6
AF11= AF5-A7
AF12= AF6-A8
AF13= AF1A15+AF2A16+AF3A17+AF4A18+AF5A19+AF6A20
AF14= AF13-BA1
AF15= AF7/AF14
AF16= AF8/AF14
AF17= AF9/AF14
AF18= AF10/AF14
AF19= AF11/AF14
AF20= AF12/AF14
AF21= A2B4
AF22= A1AF21
AF23= AF22-AF13-A21-A23
AF24= if(NH3<1000) NH32.51.25 else (500+NH32)1.25 ####this is the minimum number from the dropdown menue
AF25= AF242
AF26= AF243
if (Q2 == "MIN"){
AF27=AF24
}
if (Q2 == "AVE"){
AF27=AF25
}
if (Q2 =="MAX"){
AF27=AF26
}
AF28= ceiling(NH3*Q1) * if(A25<2) B5 else B6
AAA= AF13+AF23+AF27+AF28
#[After Area]
RA1= AF14*(1-Q3)
RA2= AF14Q3
RA3= AF7(1-Q3)
RA4= AF8*(1-Q3)
RA5= AF9*(1-Q3)
RA6= AF10*(1-Q3)
RA7= AF11*(1-Q3)
RA8= AF12*(1-Q3)
RA9 = RA3+A3
RA10= RA4+A4
RA11= RA5+A5
RA12= RA6+A6
RA13= RA7+A7
RA14= RA8+A8
RA15= RA2/NH2
RA16 = RA9/AF13
RA17= RA10/AF13
RA18= RA11/AF13
RA19= RA12/AF13
RA20= RA13/AF13
RA21= RA14/AF13
RA22= RA15/AF13
RA23= (AF7-RA3)/RA2
RA24= (AF8-RA4)/RA2
RA25= (AF9-RA5)/RA2
RA26= (AF10-RA6)/RA2
RA27= (AF11-RA7)/RA2
RA28= (AF12-RA8)/RA2
RA29= AF23RA16
RA30= AF23RA17
RA31= AF23RA18
RA32= AF23RA19
RA33= AF23RA20
RA34= AF23RA21
RA35= AF23*RA22
RA36= RA29+RA9
RA37= RA30+RA10
RA38= RA31+RA11
RA39= RA32+RA12
RA40= RA33+RA13
RA41= RA34+RA14
RA42= RA35+RA15
RA43= RA16AF27
RA44= RA17AF27
RA45= RA18AF27
RA46= RA19AF27
RA47= RA20AF27
RA48= RA21AF27
RA49= RA22*AF27
RA50= RA16AF28
RA51= RA17AF28
RA52= RA18AF28
RA53= RA19AF28
RA54= RA20AF28
RA55= RA21AF28
RA56= RA22*AF28
#VALUE EVALUATION
VA1= (A3+A9)/3.3A26
VA2= (A4+A10)/3.3A27
VA3= (A5+A11)/3.3A28
VA4= (A6+A12)/3.3A29
VA5= (A7+A13)/3.3A30
VA6= (A8+A14)/3.3A31
VA7 = VA1NH12
VA8 = VA2NH13
VA9 = VA3NH14
VA10= VA4NH15
VA11= VA5NH16
VA12= VA6NH17
VA19= VA7+VA8+VA9+VA10+VA11+VA12
VA13= VA1A15
VA14= VA2A16
VA15= VA3A17
VA16= VA4A18
VA17= VA5A19
VA18= VA6A20
VA20= VA13+VA14+VA15+VA16+VA17+VA18
VF1= RA36/3.3A26Q4
VF2= RA37/3.3A27Q4
VF3= RA38/3.3A28Q4
VF4= RA39/3.3A29Q4
VF5= RA40/3.3A30Q4
VF6= RA41/3.3A31Q4
VF7= RA42/3.3*mean(A26,A27,A28,A28,A30,A31)*Q4
VF8 = VF1NH12
VF9 = VF2NH13
VF10= VF3NH14
VF11= VF4NH15
VF12= VF5NH16
VF13= VF6NH17
VF14= VF1A15
VF15= VF2A16
VF16= VF3A17
VF17= VF4A18
VF18= VF5A19
VF19= VF6A20
VF20= VF7*NH2
VF21= VF8+VF9+VF10+VF11+VF12+VF13
VF22= VF14+VF15+VF16+VF17+VF18+VF19+VF20
CA0= if(A2>=2.8) B7 else if(A2<2.5) B9 else B8
CA1= RA36+RA43+RA50
CA2= RA37+RA44+RA51
CA3= RA38+RA45+RA52
CA4= RA39+RA46+RA53
CA5= RA40+RA47+RA54
CA6= RA41+RA48+RA55
CA7= RA42+RA49+RA56
CA8= CA1/3.3CA0
CA9= CA2/3.3CA0
CA10= CA3/3.3CA0
CA11= CA4/3.3CA0
CA12= CA5/3.3CA0
CA13= CA6/3.3CA0
CA14= CA7/3.3CA0
CA15= AAA/3.3CA0
CA16= CA1B10/3.3
CA17= CA2B10/3.3
CA18= CA3B10/3.3
CA19= CA4B10/3.3
CA20= CA5B10/3.3
CA21= CA6B10/3.3
CA22= CA7B10/3.3
CA23= AAAB10/3.3
CA24= (CA8 +CA16)*A15
CA25= (CA9 +CA17)*A16
CA26= (CA10+CA18)*A17
CA27= (CA11+CA19)*A18
CA28= (CA12+CA20)*A19
CA29= (CA13+CA21)*A20
CA30= (CA14+CA22)*NH2
CA31= CA15+CA23
CB1= VA1Q5
CB2= VA2Q5
CB3= VA3Q5
CB4= VA4Q5
CB5= VA5Q5
CB6= VA6Q5
CB7= CB1B11B12
CB8= CB2B11B12
CB9= CB3B11B12
CB10= CB4B11B12
CB11= CB5B11B12
CB12= CB6B11B12
CB13= CB7NH12
CB14= CB8NH13
CB15= CB9NH14
CB16= CB10NH15
CB17= CB11NH16
CB18= CB12NH17
CB19= CB13+CB14+CB15+CB16+CB17+CB18
CC1= B13VA1
CC2= B13VA2
CC3= B13VA3
CC4= B13VA4
CC5= B13VA5
CC6= B13VA6
CC7= B13B15CC1
CC8= B13B15CC2
CC9= B13B15CC3
CC10= B13B15CC4
CC11= B13B15CC5
CC12= B13B15CC6
CC13= B14CC1
CC14= B14CC2
CC15= B14CC3
CC16= B14CC4
CC17= B14CC5
CC18= B14CC6
CC19= (CC1+CC7+CC13)*NH4
CC20= (CC2+CC8+CC14)*NH5
CC21= (CC3+CC9+CC15)*NH6
CC22= (CC4+CC10+CC16)*NH7
CC23= (CC5+CC11+CC17)*NH8
CC24= (CC6+CC12+CC18)*NH9
CC25= CC19+CC20+CC21+CC22+CC23+CC24
#Profit
PF1= VF1NH4
PF2= VF2NH5
PF3= VF3NH6
PF4= VF4NH7
PF5= VF5NH8
PF6= VF6NH9
PF7= VF7*NH2
BBB= PF1+PF2+PF3+PF4+PF5+PF6+PF7
#RESULT
CCC= CA31+CB19+CC25
DDD= CCC-BBB
#ANALYSE
AN1= VF21/(VA19+CCC)
AN2= DDDRA23
AN3= DDDRA24
AN4= DDDRA25
AN5= DDDRA26
AN6= DDDRA27
AN7= DDDRA28
AN8= if(AN1<1.1) "low" else if (AN1<1.2) "aver" else if(AN1<1.3)"hi" else "ext"
#T1 output for OT1
Var0<- c('A-TYPE', 'B-TYPE', 'C-TYPE', 'D-TYPE', 'E-TYPE', 'F-TYPE')
Var1<- c(A15, A16, A17, A18, A19, A20)
Var2 <- c(A3, A4, A5, A6, A7, A8)
Var3 <- c(A9, A10, A11, A12, A13, A14)
Var4 <- c(A3+A9, A4+A10, A5+A11, A6+A12, A7+A13, A8+A14)
T1<- data.frame(Var0, Var1, Var2, Var3, Var4)
T1=T1
#size = AN1
#T2 output for OT2
VarA<- c('A-TYPE', 'B-TYPE', 'C-TYPE', 'D-TYPE', 'E-TYPE', 'F-TYPE', 'NEW-TYPE')
VarB<- c(NH4, NH5, NH6, NH7, NH8, NH9, NH2)
VarC<- c(RA9, RA10, RA11, RA12, RA13, RA14, RA15)
VarD<- c(RA29, RA30, RA31, RA32, RA33, RA34, RA35)
VarE<- c(RA9+RA29, RA10+RA30, RA11+RA31, RA12+RA32, RA13+RA33, RA14+RA34, RA15+RA35)
VarF<- c(AN2, AN3, AN4, AN5, AN6, AN7, 0)
T2 <- data.frame(VarA, VarB, VarC, VarD, VarE, VarF)
size = percent(AN1)
size2= AN8
T2 <- as.data.frame(T2)
return(list(size=size, size2=size2))
}
############end of calculations##################################
markers rainbow colors
r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()
#getmap
adm <- getData('GADM',SouthKorea_AL2.GeoJson, country='South korea', level=2)
data <- read.csv("mock_DATA.csv") # this is just the markers location and values (test)
data <-data[complete.cases(data),] #remove empty cell data
data$long <- as.numeric(data$long) #to make sure this is a numeric column not text
data$lat <- as.numeric(data$lat)
data$results <- as.numeric(data$results)
#mock_DATA create legend range to define the type as following
data$resultsvalue = cut(data$results,
breaks = c(1, 110, 120, 130, 200), right=FALSE,
label =c("Low[1-110)", "average[110-120)", "high[120-130)", "strong[130-200"))
#define a color pallete corresponding to the lagend result range, the color sequence correspond with the breaks=c 1,110,120,130
pal = colorFactor(palette = c("red", "yellow", "green", "blue"), domain = data$results)
data.SP <- SpatialPointsDataFrame(data[,c(2,3)], data[, c(2,3)]) # to add markers
ui <- fluidPage(
titlePanel(title = "songnam real state map developement"),
sidebarLayout(position = "left",
sidebarPanel("sidebat panel",
selectInput("dataset", "choose district", as.list(city$cityDistrict)),
selectInput("dataset", "choose neighborhood", as.list(city$neighborhood)),
numericInput("Q1", "1:", value= 1.5, min = 0, max = 1, step = 0.1),
selectInput ("Q2", "alternative:", choices = c("MIN", "AVE", "MAX")),
numericInput("Q3", "3:", value = 0.5,min = 0, max = 1, step = 0.1),
numericInput("Q4", "4", value = 1.12,min = 0, max = 1, step = 0.01),
numericInput("Q5", "5:", value = 0.4,min = 0, max = 1, step = 0.1),
numericInput("Q6", "6", value = 0.03,min = 0, max = 1, step = 0.1),
submitButton("submit")),
mainPanel("main panel",
leafletOutput("map"),
textOutput("text_calc"),
br(),
dataTableOutput('OT1'),
dataTableOutput('OT2')
)
)
)
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet(data = data, options = leafletOptions(minZoom =0, maxZoom = 50)) %>%
setView(lng =127.1389, lat = 37.4449, zoom =12)%>%
addTiles(options = providerTileOptions(noWrap = TRUE)) %>% # Add default OpenStreetMap map tiles
addCircleMarkers(data = data, lng= ~long, lat = ~lat, color = ~ pal(results), label = paste ("result=", data$results, "Type=", data$resultsvalue), popup = ~district, clusterOptions = markerClusterOptions(), layerId= ~district, clusterId = "district")%>%
#addLegend(data=data, position = "bottomright", pal = pal, values = data$resultsvalue, title = 'land value range', opacity = 1)%>%
#addMarkers(data = data, lng= ~long, lat = ~lat, popup = ~district, clusterOptions = markerClusterOptions(), clusterId = "district") %>%
addPolygons(data=adm, color = "#444444", weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 0.5,
#fillColor = ~colorQuantile("YlOrRd", ALAND)(ALAND),
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
label = ~NAME_2,
layerId = ~NAME_2
)
#addProviderTiles(providers$MtbMap) %>%
#addProviderTiles(providers$Stamen.TonerLines,
#options = providerTileOptions(opacity = 0.9))
#addProviderTiles(providers$Stamen.TonerLabels)
#readOGR("shp/cb_2013_us_state_20m.shp",
#layer = "cb_2013_us_state_20m", GDAL1_integer64_policy = TRUE)%>%
})
output$text_calc <- renderText({
Q1 <- input$Q1
Q2 <- input$Q2
Q3 <- input$Q3
Q4 <- input$Q4
Q5 <- input$Q5
Q6 <- input$Q6
paste("The result is =", mod1(Q1,Q2,Q3,Q4,Q5,Q6))
})
output$OT1 <- renderDataTable({
T1
})
output$OT2 <- renderDataTable({
T2
})
}
shinyApp(ui=ui,server= server)