CountrySelection := proc() description "Create an interface for selecting countries using checkboxes, available datasets using comboboxes, and update a plot using a button"; uses DTL = DocumentTools:-Layout, DTC = DocumentTools:-Components; global _SelectedCountries; local CountryList := GetElementNames( DataSets:-Builtin:-Reference("country") ); local CountryListStrings := map( (x)-> cat("\"",x,"\""), CountryList ); #The following list was compiled from any available datasets in the built-in "country" dataset with time series data. local TSDatasets := ["CO2 Emissions", "CPI Change", "Child Mortality", "Fertility Rate", "GDP - LCU", "GDP - USD", "GDP Deflator", "Gini Index", "Internet Users", "Population", "Real GDP - LCU", "Real GDP Change", "Adult Literacy Rate", "Adults Living with HIV", "Armed Forces Personnel", "Cell Phone Subscribers", "Commercial Tax Rate", "Exports Share of GDP", "Female Population", "Government Revenues", "Government Spending", "Gross Production", "Imports Share of GDP", "Industry Share of GDP", "Low Birth-Weight Babies", "Military Expenditures", "Nurses per 1000 People", "Passenger Vehicles", "Population Above Age 64", "Population Below Age 15", "Population Density", "Population Growth Rate", "Primary Enrolment Rate", "Rural Population", "Services Share of GDP", "Surplus or Deficit", "Tertiary Enrolment Rate", "Urban Population", "Youth Literacy Rate", "Agriculture Share of GDP", "Deaths From Injury and Accident", "Female-Male Literacy Ratio", "Gross Inland Availability", "Health Expenditure Per Capita", "Household Electrification Rate", "Life Expectancy at Birth", "Nominal USD Exchange Rate", "Population Aged 15 to 64", "Secondary Enrolment Rate", "Urban Population in Slums", "Access to Improved Water Sources", "Deaths From Disease and Nutrition", "Deaths From Non-Communicable Diseases", "Access to Improved Sanitation Facilities", "Population Affected by Droughts or Floods"]: local CB := i -> DTC:-CheckBox( i, 'identity' = i, 'action' = cat( "if not eval( :-_SelectedCountries )::Matrix then\n", " :-_SelectedCountries := Matrix(1,1,[table([])]):\n", "end if;\n", "if not eval( :-_SelectedCountries[1,1][\"","Update_Button","\"] )::table then\n", " :-_SelectedCountries[1,1][\"","Update_Button","\"] := table([]):\n", "end if;\n", "if DocumentTools:-GetProperty(\"", i, "\", value ) = \"true\" then\n", " :-_SelectedCountries[1,1][\"","Update_Button","\"][ DocumentTools:-GetProperty( \"", i, "\", 'caption' ) ] := DocumentTools:-GetProperty( \"", i, "\", 'caption' ):\n", "else\n", " :-_SelectedCountries[1,1][\"","Update_Button","\"][ DocumentTools:-GetProperty( \"", i, "\", 'caption' ) ] := evaln( :-_SelectedCountries[1,1][\"","Update_Button","\"][ DocumentTools:-GetProperty( \"", i, "\", 'caption' ) ] ):\n", "end if;" ) ); local lkup; if not assigned( :-_SelectedCountries ) then :-_SelectedCountries := Matrix( 1, 1, [table()] ): #Collects selected countries end if; lkup := DocumentTools:-InsertContent( 'output' = table, DTL:-Worksheet( DTL:-Section( 'collapsed' = false, Title( DTL:-Textfield( 'style' = Heading1, 'layout' = Heading1, 'alignment' = left, "Country Selector" ) ), DTL:-Table( DTL:-Row( seq( DTL:-Input( seq( DTL:-Textfield( `if`( i+j*24 <= numelems( CountryList ), CB( CountryList[ i+j*24 ] ), " " ), 'alignment' = left ), i = 1..24) ), j = 0..7 ) ) ) ), DTL:-Table( DTL:-Column()$4, DTL:-Row( DTL:-Cell("X:", 'fillcolor' = "WhiteSmoke"), DTL:-Cell("Y:", 'fillcolor' = "WhiteSmoke"), DTL:-Cell("Bubble Size:", 'fillcolor' = "WhiteSmoke"), DTL:-Cell("", 'fillcolor' = "WhiteSmoke") ), DTL:-Row( DTL:-Input( DTL:-Textfield( DTC:-ComboBox( TSDatasets, 'identity' = "ComboBox_0", 'selected' = "Internet Users" ) ) ), DTL:-Input( DTL:-Textfield( DTC:-ComboBox( TSDatasets, 'identity' = "ComboBox_1", 'selected' = "GDP - USD" ) ) ), DTL:-Input( DTL:-Textfield( DTC:-ComboBox( TSDatasets, 'identity' = "ComboBox_2", 'selected' = "Population" ) ) ), DTL:-Cell( DTL:-Input( DTL:-Textfield( DTC:-Button( "Update", 'identity' = "Update_Button", 'action' = cat( "try\n", "DocumentTools:-SetProperty( \"", "Data_Plot", "\", 'value',\n", "Statistics:-BubblePlot( Vector([((x) -> DataSets:-Builtin:-Reference(\"country\")[x, DocumentTools:-GetProperty( \"", "ComboBox_0", "\", 'value' )])~( [entries(:-_SelectedCountries[1,1][\"","Update_Button","\"], nolist, indexorder) ] ) ] )\n", " , Vector([((x) -> DataSets:-Builtin:-Reference(\"country\")[x, DocumentTools:-GetProperty( \"", "ComboBox_1", "\", 'value' )])~( [entries(:-_SelectedCountries[1,1][\"","Update_Button","\"], nolist, indexorder) ] ) ] )\n", " , Vector([((x) -> DataSets:-Builtin:-Reference(\"country\")[x, DocumentTools:-GetProperty( \"", "ComboBox_2", "\", 'value' )])~( [entries(:-_SelectedCountries[1,1][\"","Update_Button","\"], nolist, indexorder) ] ) ] )\n", ", 'data_legend' = [ DocumentTools:-GetProperty( \"", "ComboBox_0", "\", 'value' ), ", "DocumentTools:-GetProperty( \"", "ComboBox_1", "\", 'value' ), ", "DocumentTools:-GetProperty( \"", "ComboBox_2", "\", 'value' ) ] ", ", 'bubble_legend' = [indices(:-_SelectedCountries[1,1][\"","Update_Button","\"], nolist, indexorder)], 'gridlines', 'font' = [\"Calibri\", 14], 'legendstyle' = [location=right]) ) \n", "catch:\n", "DocumentTools:-SetProperty( \"", "Data_Plot", "\", 'value', plots:-textplot( [1,1,\"Error in DataSet retrieval\"], 'axes' = none ) );\n", "end try:\n" ) ), DTC:-Button( "Clear", 'identity' = "Clear_Button", 'action' = cat( ":-_SelectedCountries[1,1][\"","Update_Button","\"] := table():\n", "seq( DocumentTools:-SetProperty( ", CountryListStrings[i], ", 'value', false ), i = 1 .. 185);\n", "DocumentTools:-SetProperty( \"", "ComboBox_0", "\", 'value', \"Internet Users\" );\n", "DocumentTools:-SetProperty( \"", "ComboBox_1", "\", 'value', \"GDP - USD\" );\n", "DocumentTools:-SetProperty( \"", "ComboBox_2", "\", 'value', \"Population\" );\n", "DocumentTools:-SetProperty( \"", "Data_Plot", "\", 'value', plot( [], 'axes' = 'none' ) );" ) ), 'alignment' = 'centered' ) ) ) ), DTL:-Row( DTL:-Cell( DTL:-Input( DTL:-Textfield ( DTC:-Plot( plot( [], 'axes' = 'none' ), 'identity' = "Data_Plot", 'pixelheight' = 600, 'pixelwidth' = 1200, 'showborders' = false ), DTC:-DataTable( 'identity' = "DataTable_0", 'variable' = '_SelectedCountries', 'visible' = false, 'visiblerows' = 1, 'visiblecolumns' = 1 ) ) ), 'columnspan' = 4 ) ) ) ) ): if eval(:-_SelectedCountries[1,1])::table then :-_SelectedCountries[1,1][lkup["Update_Button"]]:=table([]); else :-_SelectedCountries[1,1]:=table([lkup["Update_Button"]=table([])]); end if; end proc: