andrea.nieves7 1 year ago
parent
commit
dfffadbf77
3 changed files with 199 additions and 0 deletions
  1. 37
    0
      R.R
  2. 73
    0
      fetchData.js
  3. 89
    0
      styles.js

+ 37
- 0
R.R View File

@@ -0,0 +1,37 @@
1
+library(tidycensus)
2
+library(tidyverse)
3
+
4
+
5
+#log on with API
6
+census_api_key("7a853acf81fd5758228680556ac831138c40b83e")
7
+
8
+
9
+
10
+callData = function(year,table,municipality) {
11
+  
12
+  #year is between 2000 and 2020
13
+  #table is dp02pr, dp03, dp04, dp05
14
+  
15
+  #load variables
16
+  variables = load_variables(year,"acs5/profile")
17
+  #load variable vectors
18
+  codes = variables$name
19
+  codesBool = startsWith(codes,table)
20
+  
21
+  codes = codes[codesBool]
22
+  labels = variables$label[codesBool]
23
+  
24
+  #pull table
25
+  bigTable = get_acs(geography = "county",
26
+                 state = "PR",
27
+                 year = year,
28
+                 county = municipality,
29
+                 variables = codes)
30
+  
31
+  bigTable$Label = labels
32
+  bigTable = bigTable[c("Label","estimate","moe")]
33
+  return(bigTable)
34
+}
35
+
36
+table = callData(2020,"DP05","Aguada")
37
+

+ 73
- 0
fetchData.js View File

@@ -0,0 +1,73 @@
1
+import * from styles
2
+import DropDownPicker from 'react-native-dropdown-picker';
3
+import React, {useState, useEffect} from 'react';
4
+
5
+
6
+//ALL REQUIRED TO GET DATA
7
+
8
+DropDownPicker.setListMode("SCROLLVIEW")
9
+
10
+//data parsing goes here
11
+function getInfo(information){
12
+	//console.log(information[6])
13
+	if(!information)
14
+	{Alert.alert("Please try again later! Error retriving data")}
15
+	else
16
+	{return information}
17
+
18
+	
19
+}
20
+
21
+
22
+//data display
23
+
24
+class DataButton extends React.Component{
25
+	
26
+	state = {
27
+		click: false
28
+	}
29
+	
30
+	pullData = () => {createQuery(pueblo, table); information = loadDoc(query); this.setState({click: true})}
31
+	
32
+	
33
+	render() {
34
+		return(
35
+		<View>
36
+			<Button
37
+			onPress = {this.pullData}
38
+			title = "Fetch Data"
39
+			color = "black"
40
+			/>
41
+			<Text style={styles.sub}>{getInfo()}</Text> 
42
+		</View>
43
+	);}	
44
+}
45
+
46
+
47
+function createQuery(pueblo, table) {
48
+	
49
+	const queryBase = "https://api.census.gov/data/2020/acs/acs5/profile?get=group"
50
+	const queryEnd = "&in=state:72"
51
+	console.log("fetching data")
52
+	
53
+	var query = queryBase + "(" + table + ")&for=county:" + pueblo + queryEnd 
54
+	
55
+	if(pueblo && table)
56
+	{return query}
57
+	else
58
+	{Alert.alert("Please fill every parameter before calling!")}
59
+	
60
+}
61
+
62
+function loadDoc(query) {
63
+  var xhttp = new XMLHttpRequest();
64
+  xhttp.onreadystatechange = function() {
65
+    if (this.readyState == 4 && this.status == 200) {
66
+         var information = this.responseText;
67
+		 return information
68
+  }
69
+  };
70
+  xhttp.open("GET", query, true);
71
+  xhttp.send();
72
+  
73
+}

+ 89
- 0
styles.js View File

@@ -0,0 +1,89 @@
1
+//styles
2
+
3
+const styles = StyleSheet.create({
4
+	
5
+  buttons: {
6
+	  flexDirection: 'row',
7
+	  justifyContent: 'center',
8
+	  marginTop: 40,
9
+	  marginBottom: 30,
10
+	  margin: 30,
11
+	  borderColor: "grey",
12
+	  borderRadius: 8,
13
+	  padding: (30, 16),
14
+	  backgroundColor: "black",
15
+	  marginTop: 0
16
+  }, 
17
+  buttonContainer: {
18
+    flexDirection: 'column',
19
+    backgroundColor: '#f0f8ff',
20
+    // alignItems: 'center',
21
+    // justifyContent: 'center',
22
+	paddingTop:40,
23
+	marginTop: 15,
24
+  },
25
+  bottom: {
26
+    flex: 0.3,
27
+    backgroundColor: "gray",
28
+    borderWidth: 5,
29
+    borderBottomLeftRadius: 20,
30
+    borderBottomRightRadius: 20,
31
+	alignItems:'center',
32
+
33
+  },
34
+  container: {
35
+    flexDirection: 'column',
36
+	justifyContent: 'center',
37
+    backgroundColor: '#f0f8ff',
38
+    alignItems: 'center',
39
+    justifyContent: 'center',
40
+	paddingTop:20,
41
+	marginTop: 15,
42
+  },
43
+
44
+
45
+  containerbackground:{
46
+	
47
+    backgroundColor: '#f0f8ff'
48
+  },
49
+  intro: {
50
+	  fontWeight: "bold",
51
+      color:"#black",
52
+	  fontSize: 30,
53
+  },
54
+
55
+  sub: {
56
+	color:"#black",  
57
+	fontWeight: "bold",
58
+	fontSize: 15,
59
+	paddingBottom:10,
60
+},
61
+
62
+  Navsub: {
63
+      color:"#black",  
64
+	  fontWeight: "bold",
65
+	  fontSize: 30,
66
+	  paddingBottom:10,
67
+  },
68
+  scrollView:{
69
+	  marginHorizontal: 20
70
+  },
71
+  listItem:{
72
+	  fontSize: 30,
73
+	  color: "white",
74
+	  textDecorationLines: "underline"
75
+  },
76
+  listButtons:{
77
+	  fontSize: 15,
78
+	  color: "white",
79
+	  textDecorationLines: "underline"  
80
+  },
81
+  buttonsVer: {
82
+	  flexDirection: 'column',
83
+	  justifyContent: 'center',
84
+	  marginTop: 40,
85
+	  marginBottom: 30,
86
+	  margin: 30,
87
+	  borderColor: "grey",
88
+  }
89
+});