r shiny slider range to graph - r

edit: to clarify, the function to make my choropleth graph require "region" (state) and "value" columns, and simply color codes the region based on where value falls on the scale.
I want to make the "value" column dynamic and have the graph reference the dynamic column
I am not sure if I can read from an output object
I have a slider range from 2000-2014, and columns x2000-x2014.
I want the slider to change the data being graphed, so if I choose 2002-2010 it shows that data, etc.
It's a choropleth graph showing % change between the two years, so if I choose 2004 and 2007 on the slider I want it to pull (x2007-x2004)/x2004. I can get it to change to X2004 (low<- paste0("X", input$range[1])) but I cant really do df$low.

If I read the question correctly then you are able to create a character string with the name of the column in the data frame that you want to access (low is the name of the column in data frame df), but your attempts to access that column using df$low is not working. Is that correct?
If so, then there is actually a fortune about this:
> library(fortunes)
> fortune('toad')
The problem here is that the $ notation is a magical shortcut and
like any other magic if used incorrectly is likely to do the
programmatic equivalent of turning yourself into a toad.
-- Greg Snow (in response to a user that wanted to access a
column whose name is stored in y via x$y rather than x[[y]])
R-help (February 2012)
The answer to your question is in the bottom part of that quote and is detailed on the help page help('$') and in section 6.1 of An Introduction to R.

Related

How to import reactive datasets in Rshiny?

i m creating a risk dashboard , the problem is that i need the data set to be reactive , i have a simple dataset composed of countries (8) , sectors and values , what i want is that my app will be able to deal with different data sets for example if we change the colnames (country becomes pays) and we change the position of the col ,the app will recognize the column as country (in reality the data set is composed of an undefined number of variables with unkown names)
for example for the country column , i thought of creating a list that contains all country names and and when the first row of a column matches with a country from that list ,the column become names country
like that the problem is solved for one variable and what about the other ones
I think that's unnecesary complexity.
I suggest you to build an script to clean your data first with those specifications and then use it as a source.
You can use pattern recognition to match columns but be sure there aren't similar columns, for example, if you have two numerical variables there's a big problem.
Via Shiny I suggest you:
fileInput to import your database
Visualizate your database using DT
Create as many textInput boxes as columns you have
Manually change colnames using dplyr::rename and the boxes
Use the transformed database in your dashboard
Other options can be made using base::grep and dplyr.

Dynamic aggregation column input reference in Spotfire TERR data function

How can I make a dropdown menu that allows me to reference different columns and change the column reference of a data function in Spotfire's TERR/R?
I am creating 2D cross plots of data, using TERR data function to overlay the average profile line of the data on top of the individual profile lines. I am trying to add the ability to toggle between different normalizations. I want to be able to see data and the average of data over time normalization, pressure normalization, etc, etc. Without having to go into the data function and change the column name reference every time I want to change.
I know how to make the dropdown in the text area and reference each visualization, so those change automatically, but I still can't figure out how to make the TERR data input column to change dynamically with the dropdown menu selection so that the average line also changes.
There must be some way to simply say I want whatever is in the document property to be the "group by" column in the TERR data function to perform aggregations against. (I'm using the R package dplyr to do various simple statistical aggregations on data)
Thanks for the help!

Cant I use dates as axes in a scatter plot in SAS VA?

In Enterprise Guide, I draw scatter plots with creation and closing date of issues to detect when backloggs occur and when they are resolved:
(The straight lines in the graph are batch interventions, like closing a set of issues that were handled outside ot the system.)
proc sgplot data=alert;
scatter x=create_Date y=CloseDate / group=CloseReason;
run;
When I try to do the same in SAS Visual Analytics, I can only put measures on the x-ax and y-ax and I cant make te date or datetime variable a measure.
Do I do something wrong? Should I use another graph type?
My take is that the inability of SAS VA Explorer to allow dates to be measures is a real weakness. Old school trickery would be perhaps to create a duplicate data item that computes the SAS data value (giving you a number result and thus a measure) and then formatting that with a custom format to render it back as a human readable date.
However, according to http://support.sas.com/kb/47/100.html#explorer
How SAS Visual Analytics Designer supports formats
In SAS Visual Analytics Designer, the Format property of the data item displays the name of the format for both numeric and character data items. However, there are some differences between numeric and character data items.
Numeric data items
You can change the format. If you change the format, you can restore the user-defined format by selecting Reset to Default in the Format type box.
You can specify to sort by formatted or unformatted values (release 6.2 and later).
(My bolds) Numeric data items with a user-defined format are classified as categories. You cannot change these data items to measures while the user-defined format is applied.
According to support.sas.com/documentation/cdl/en/vaug/68648/PDF/default/vaug.pdf , page 166, you could work on defining data roles for a scatter plot.
I am not sure that this could solve your situation but it says that:
"In addition to measures, you can assign a Group variable. The Group variable groups the data based on the values of the category data item that you assign. A separate set of scatter points is created for each value of the group variable.
You can add data items to the Data tips role. The values for the data items in the Data tips role are displayed in the data tips for the scatter plot".
Hope it helps.

Adding a column from a dataframe to a SpatialPolygon Dataframe

I've been trying to add a column of numerical data from a dataframe to a SpatialPolygon dataframe but every attempt leads to the latter dataframe being converted to a standard dataframe similar to the former. I needed to add the column so that I can create a choropleth map with the column's variable as the focus. Obviously the standard dataframe is no good since I'm trying to create a map using tmap.
This is how I've been trying to add the column (where shapefilecomb is the spatial dataframe and wardturnout is the variable containing the column in question):
shapefilecomb <- c(wardturnout)
Adding a column into data slot of SpatialPolygonsDataFrame by assignment operator shapefilecomb$wardturnout <- wardturnout works, but it is not the safest way to do the job. It relies only on position (first data item goes to first polygon, second to second and so on). It can get messy.
It is best reserved for calculated fields - the shapefile$valuepercapita <- shapefile$value / shapefile$population kind of assignment.
For data from external sources it is much better idea to assign value by key. Function append_data from tmap package does it very nicely, and gives you a message not only when error occurs, but also confirmation when all data was matched perfectly (which I found as a nice touch when working with large sets of imperfect data).
outShape <- append_data(srcShape, frmData, key.shp = "KOD_LAU1", key.data = "LAU1")
Edit (as of 9/2019): This answer seems to be still going strong... The world has changed though.
tmap::append_data() has been moved to tmaptools::append_data()
and is by now deprecated
sf has replaced sp as the go-to package in spatial data in R
In
the sf world spatial data are stored in modified data.frames, and the
most appropriate way to assign data items by key is one of the
*_join() functions from dplyr - either dplyr::left_join() to be
on safe side, or dplyr::inner_join() if filtering on both sides is actually desired behavior.

JasperReports CategoryDataset has less data than expected?

I'm trying to develop a ChartCustomizer that takes the data from a chart and converts it into a histogram (because JR does not directly support histograms). It's a fairly simple implementation with hard-coded intervals, etc. mostly as a proof-of-concept at this point.
The data I'm analyzing is HTTP response-time data of the form [date, response-time] and I have a CSV file with 18512 records in it. In my summary band, I have 3 items:
A text field dumping $V{REPORT_COUNT} (it reports 18512 in iReport's report preview)
A time series showing all the data points [date, response-time]
A category plot containing all the data points in a single series [category=$F{DATE}, value=$F{RESPONSE_TIME}]
I decided that the most straightforward way to build a histogram would be to use the Category plot because it had the right structure for the final histogram chart.
When the ChartCustomizer runs, it dumps out all kinds of good information about the data set, including the size. Strangely, the size is 10252: it's missing something like 8000 data points. I can't understand why the category plot would have fewer data points than the whole data set.
Any ideas?
Answering my own question in case others run across this foolish user error.
The problem was that CategoryDataset only allows one data point per "category", and in my case, "category" was a java.util.Date captured from the web server log. Apparently, nearly half of my dates were duplicates and so part of the data set overwrote the other half, leaving a subset of the data.
That should have been totally obvious to me at the outset, because that is exactly how a category dataset works.
Anyhow, simply changing the category plot series's "category expression" from $F{DATE} to $V{REPORT_COUNT} gave each datum a unique category which makes everything work.

Resources