Watts-College / cpp-529-fall-2021

https://watts-college.github.io/cpp-529-fall-2021/
0 stars 0 forks source link

Adding interpretable variable names in building dashboard #14

Open lghb2005 opened 2 years ago

lghb2005 commented 2 years ago

Hi professor Howell,

I hope you are doing well! I have got an issue with adding interpretable variable names in building the dashboard. I tried to enable and run the choices = temp.names for demographics, chunk 3 in the template. However, when I rendered the dashboard, no choropleth maps showed up but reported errors "cannot find the variables selected."

While figuring out this issue, could you please explain a bit about the following codes included in the template? I guess I would need to understand those lines better to do things properly.

# Adding interpretable variable names
# from the data dictionary:
# add a name attribute for each variable
# 
# value <- c(1,2,3)
# dd.name <- c("one","two","three")
# 
# x <- dd.name
# names(x) <- value
#
# dd names and values linked
# names( x[2] )
#
# can now get the label using the value
# using the name attributes 
# x[ "two" ]
#
# to add labels to the maps
# use the radio button value 
# to get the data dictionary label: 
#
# x[ input$demographics ]

Much appreciated in advance, and I wish you a wonderful weekend!

Best, Robin

lghb2005 commented 2 years ago

Hi professor @AntJam-Howell , in case you miss my post above. Could you please take a look at my question above? Many thanks~

AntJam-Howell commented 2 years ago

@lghb2005 I believe the problem is likely some of the variables in temp.names may not have been loaded in or renamed properly. From our previous labs, you can try something like this:

these.variables <- c("pnhwht12", "pnhblk12", "phisp12", "pntv12", "pfb12", "polang12", 
"phs12", "pcol12", "punemp12", "pflabf12", "pprof12", "pmanuf12", 
"pvet12", "psemp12", "hinc12", "incpc12", "ppov12", "pown12", 
"pvac12", "pmulti12", "mrent12", "mhmval12", "p30old12", "p10yrs12", 
"p18und12", "p60up12", "p75up12", "pmar12", "pwds12", "pfhh12")
names(these.variables) <- c( "White", "Black", "Hispanic", "Native America", "Foriegn", "Other Language", "HS Degree", "College Degree", "Unemployed", "Female Workforce", "Professionals", "Manufacturers", "Veterans", "Self Employed", "Household Income", "Income per Capita", "Poverty", "Owner-Occupied Units", "Vacant Units", "Multifamily Units", "Median Rent", "Median House Value", "Structures > 30yrs", "HH < 10yrs", "17 and Under", "60 and Up", "75 and Up", "Married", "Widowed, Divorced, Separated", "Families with Children" )
radioButtons( inputId="demographics", 
              label = h3("Census Variables"),
              choices = these.variables, 
              #choiceNames=temp.names,
              #choiceValues=these.variables,
              selected="pnhwht12")

The examples that you show relate mainly to different approaches to renaming variables and indexing dataframes. You can play around with the examples in a separate .R document to see the mechanics of how each line of code is working.

lghb2005 commented 2 years ago

Thanks a lot for your suggestions@AntJam-Howell ~ I will look into that and play those codes around!