简体   繁体   中英

r shiny slider range to graph

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM