1 Reply Latest reply on Sep 30, 2018 1:15 PM by Jonathan Drummey

    Tableau and R --> multiple values in filter

    ukasz.gierada.0

      Hi guys,

       

      I am trying to integrate Tableau and R. I successfully connect everything and at some point I see it works. However, I need to pass more than one value from filter to the file and here I have a problem.

      I understand all values have to be aggregated once using R but in that case, I won't be able to see all values I have selected in filter.

      Can anyone advise here? I attached Workbook

       

      Desired outcome? To see selected values from Segment filter in file created on Desktop

       

      SCRIPT_STR(

       

       

      'library("future")

      plan(multiprocess)

      fun2 <- function() {

      Sys.sleep(1)

        fileConn<-file("C:\\Users\\xxx\\Desktop\\output2.txt")

        writeLines(c("Hello","'+MAX([Segment])+'"), fileConn)

        close(fileConn)

       

       

      }

      future(fun2())

      print("Test 24.10")',MAX([Sales]))

       

      Jonathan Drummey Maybe you can help here?

        • 1. Re: Tableau and R --> multiple values in filter
          Jonathan Drummey

          Hi,

           

          Using the R connection to do a write back is not a designed-for use of R. Tableau will overwrite the file *a lot*, there are many actions that can trigger a viz refresh such that the R will be written back to, and then there are times when Tableau won't make any changes at all, and whether something triggers a write back or not could change from one version of Tableau to the next.

           

          Also when using Tableau's calculations the calculations don't have access to selected values in the filter, instead we see the selected values that are *in the data*. This is a subtle but sometimes critical distinction. If you actually want to see what users are selecting then you'll need to use Tableau's JavaScript API. If you're ok with the list of selected values that are in the data then you can set up the R calculation to compute over the vector of values sent, I set up examples in the attached v2018.2 workbook.

           

           

          Jonathan