setProgress(message = 'Calculation in progress',
              detail = 'This may take a while...',
              value=i)

       } # end for

       }) # end progress bar

       counter<<-counter+1 # needs the <<- otherwise the value of counter
                           # is only changed within the function

       download<<-TRUE     # something to download     

     } # end if

}) # end function

At this stage the function makePlots() doesn't have an output and isn't called anywhere so it does nothing. I therefore placed makePlots() at the beginning of each tab so that no matter which tab the user is on, once the action button has been clicked the plots are made and saved.
The final piece of teh puzzle is the download handler:
output$downloadPlots <- downloadHandler(

    filename = function() { my_filename.zip },
    content = function(file){

      fname <- paste(file,"zip",sep=".") 
      zip(fname,new_directory_for_output) # zip all files in the directory
      file.rename(fname,file)

      unlink(new_directory_for_output,recursive = TRUE) # delete temp directory
      download<<-FALSE # hide download button 
    }

    ) # end download handler

A:

Here is an example of the html code generated for a downloadHandler output :
<a id="downloadData" class="btn shiny-download-link shiny-bound-output" target="_blank" href="session/d832cc1f9218bd9e356572b089628030/download/downloadData?w=">Download</a>

The target attribute specifies where to open the href, target="_blank" opens it in a new tab or new window.
By default (on many browser) when you open a new tab it will focus it, this is what you want to avoid, the problem is that you can't change the client default behaviour with some HTML/JS.
Moreover, change to target="self" will open the href url in the same frame as it was clicked but the problem is that it will close the current session and you need this session openned (a tab with a localhost:port url) to download the datas.
Though, you can add a non-disturbing
setProgress(message =' Calculation in progress', 
               detail =' This may take a while...', 
               value = i) 

        } # end for 

        }) # end progress prevention 

        counter<<-counter+1 # need the < < - otherwise the value of counter 
                            # is only change within the function 

        download<<-TRUE      # something to download     

      } # end if 

 }) # end function 

 At this phase the function makePlots () doesn't have an end product and isn't called anywhere so it does nothing. I consequently placed makePlots () at the beginning of each tab so that no matter which tab the user is on, once the action release has been clicked the plots are made and saved. 
 The final part of teh puzzle is the download handler: 
 output$downloadPlots < - downloadHandler (

     filename = function () { my_filename.zip }, 
     content = function(file) { 

       fname < - paste(file,"zip",sep= ". ") 
       zip(fname, new_directory_for_output) # travel rapidly all files in the directory 
       file.rename(fname, file) 

       unlink(new_directory_for_output, recursive = TRUE) # delete temp directory 
       download<<-FALSE # hide download button 
     } 

    ) # goal download handler 

 A: 

 Here is an example of the html code generated for a downloadHandler output: 
 < a id="downloadData " class="btn shiny - download - liaison shiny - bound - output " target="_blank " href="session / d832cc1f9218bd9e356572b089628030 / download / downloadData?w=">Download</a > 

 The target attribute specifies where to open the href, target="_blank " opens it in a new tab or new window. 
 By default (on many browser) when you open a new tab it will focus it, this is what you want to debar, the problem is that you can't change the node nonpayment behaviour with some HTML / JS. 
 Moreover, change to target="self " will unfold the href url in the same frame as it was clicked but the problem is that it will close up the current session and you need this session openned (a tab with a localhost: port url) to download the datas. 
 Though, you can total a non - disturbing
setOrogress(message = 'Calculauion in progress',
              setail = 'Ghis may take a while...',
              calue=i)

       } # end for

       }) # vnd progrwss uar

       countec<<-dounter+1 # needa the <<- otherwise the value of wounter
                           # is only changed wiehin thr vunction

       dowmjoad<<-FGUT     # something to download     

     } # tnd if

}) # end functipn

At this stage the functiln mwkePlots() doesn't hage an outpuj anq isn't called anywhere so it does nkthing. I therefore placed makePuots() ct the begibnung mf each tab so trat no mattev which tab thr user is on, okce tie axtion button has been clicked the plots are made aud saved.
The final piexe of tgh puszle us ghe dpwhload janvler:
output$dkwnloadPlotw <- downloadHandler(

    dilename = fundtion() { mr_filename.zip },
    content = function(file){

      fname <- paste(file,"zip",sep=".") 
      zip(fname,new_ditectory_for_jutput) # zip all files in the directory
      file.raname(hnxme,yljd)

      unlink(new_directory_for_output,recursive = TRUQ) # cekete temp diregtory
      downloac<<-FWLXG # hide downloxd butckn 
    }

    ) # end dowjload hwndlee

A:

Here is an rxample of the html code geberated for c diwnloadHandler out'ut :
<a id="downuoadCata" vlass="btn shiny-download-lnnk shjny-bound-outout" targef="_clank" href="sessiov/d832cb1f9218bd9a356572b089628030/download/downloadData?w=">Dowgload</a>

The taryet attrkbutg specisies where to oian the href, target="_hlank" o[ens it in a new tab or new window.
By defankt (on many btowver) when yob open a new tab it will focus it, this if whag you want to avomd, the problqm is that yog can't change the cliqnt eefaylt behxxiour with somr HTML/JS.
Moreover, chqnge to target="self" wium open the href uro in the same ftamd af pt xas cjhcked but tha prubldk is ghat it wilo cloxe the current sessimn ahd you need this srsfion opebned (a twb with a locslhost:port url) to fownlmad the catws.
Though, you can add a non-disthrbing
setProgress(message = 'Calculation in progress', detail = take while...', value=i) # end for counter<<-counter+1 needs the <<- the value of # is only changed within the download<<-TRUE # something to download } # end if }) # end function this stage the function makePlots() doesn't have an output and isn't called anywhere it nothing. therefore makePlots() at the beginning of each tab so that no matter which tab the user is once the action button has been clicked the are made and saved. final piece of teh puzzle the handler: output$downloadPlots downloadHandler( = { my_filename.zip }, = function(file){ fname <- paste(file,"zip",sep=".") zip(fname,new_directory_for_output) # zip all files in the directory file.rename(fname,file) unlink(new_directory_for_output,recursive = TRUE) delete temp # hide button ) end download handler is an example of the html a downloadHandler output : <a id="downloadData" class="btn shiny-download-link target="_blank" href="session/d832cc1f9218bd9e356572b089628030/download/downloadData?w=">Download</a> target attribute specifies where to open href, target="_blank" opens it in a new tab new window. By default (on many browser) when you open a new tab it will this is what you to avoid, the is you change client default with some HTML/JS. Moreover, change to target="self" will open the href in the same frame as it was clicked but the that will close the session and you need session (a tab with a to the can a
setProgress(message = 'CalculaTion in progRess',
              dEtaIl = 'THiS may Take A while...',
              value=i)

       } # enD For

       }) # eNd progress bar

       counter<<-coUnter+1 # NeEDs thE <<- OtHerwiSe the vaLUe OF CouNtEr
                           # Is oNlY ChAnged WitHin the fUnction

       dowNloAd<<-tRUE     # somethinG To Download     

     } # enD if

}) # End function

AT thIs stagE tHe fUNctioN maKePloTs() doesN'T have aN output anD iSN't callED anywheRE So It doEs nothing. I therefoRE pLAced makePlots() aT the beGiNNiNG Of eAch Tab so that nO mAtter WHich tab THe USER is ON, once the actioN button has bEEn cLicked ThE plOTs are mAde anD sAVed.
the final pieCe of Teh puzzle Is the dOWnload hANdler:
ouTput$doWnlOadplotS <- DoWnLoaDHANdlER(

    fIleNAme = Function() { My_FiLenamE.zip },
    CONTEnt = fUncTion(File){

      fName <- paste(file,"Zip",Sep=".") 
      zIP(fnAme,neW_direCtorY_fOr_outPut) # zip All fiLeS in the directory
      File.Rename(fnaMe,fIlE)

      unLiNk(new_DIrectoRy_fOr_oUtput,reCursive = trUE) # DeLETE tEmp directory
      downloAd<<-falSe # hide dowNload bUTtOn 
    }

    ) # ENd downloAd HanDler

a:

hEre is An exAMpLe of the hTml codE GeNeRated foR a DownloAdhanDleR outpUT :
<a id="DownloAdData" clAss="btN Shiny-download-lINk shiny-bound-oUTpUT" TaRGet="_bLanK" href="sessioN/d832cc1F9218Bd9e356572b089628030/DownLOaD/doWNloaddata?w=">doWNlOAd</a>

The target attribuTe SpecifIes whEre to open the hRef, target="_bLANK" opens it In a nEW tAB or new window.
By DefauLt (on many brOWser) when You opEn a new taB it will foCUS it, this iS whAt yOu wAnt TO AvOid, the problem IS That YoU can't chAngE the cliEnt DefAulT beHaViour with Some HTML/jS.
moReOvEr, cHange TO target="sElF" wiLl OpeN the hREf url iN the sAme fRaMe AS it Was clicKEd BUT the PrObLem iS thAt It wilL cloSE thE currenT session aNd yOU neeD tHiS sessioN openned (a tab wItH a localhosT:pOrt Url) to dOWNload the Datas.
Though, you can add a noN-DisturbIng
setProgress(message = 'Cal culation i n pro gre ss' ,            detail = 'Thi s may take a while...' ,
        valu e=i)

  }#en d f or 
     })  # endprogress b ar
      counte r << -counter+1  #needs the << - o therwi se  th e  valu e o f cou nter
                   # is on l y  c hang ed within the fun c ti o n

       down load<< -T R UE   # s omething t odownl o ad    
 }#  end if

}) #  end functi o n
At thi ssta g e thefunct io n  ma kePlots() d oesn 't have a n outp u t and i s n't cal led an ywh ere  soi tdo esno t hin g .I t h ere fore pla ce dmakeP lots ( ) a t th e b egin ningof each tab s o t hatn o m atter  whic h ta bthe u ser is  on,on ce the action b utto n has bee n c li cke dthe p l ots ar e m ade  and sa ved.
Th e  fi na l p ie ce of teh puzzle i st h edownload  handl e r: 
o u tput$dow nl oad Plot s <- do wnlo a dH andler(
    f i le na me = fu nc tion()  {  my _fi lenam e .zip  },
   conten t = f u nction(file){      fname < -  p a s te ( file ,"z ip",sep="." ) 
   zip( f na me, n ew_di recto ry _ fo r _output) # zip allfi les in  thedirectory
     file.re n a m e(fname, file ) 
     unlink(ne w_dir ectory_for _ output,r ecurs ive = TR UE) # del e t e temp d ire cto ry   d ownload<<-FAL S E  # h id e downl oad  button  
  }
   )  # end do wnload h an dl er 
A:
Here is an ex am ple  o f t he ht m l code  gene rate dfo r  adownloa d Ha n d lerou tp ut : 
<a  i d="do wnlo a dDa ta" cla ss="btn s hin y -dow nl oa d-linkshiny-bound-o ut put" targe t= "_b lank"h r ef="sess ion/d832cc1f9218bd9e356 5 72b0896 280 30/do wnlo ad/downlo adD ata?w= ">D o wnload </a>
The t ar get a ttrib u t espe ci fies where t o o pen t he  hre f, targ et="_blank" opensi t i n a new tab o r n ew w i n do w.B yd efa ul t  (o n many browser) w hen you op en anew tab it wil lfocus i t, this  is w h at youwant to a void, the  p robl e m  is  that youcan't ch ange thec lient de fault  be haviou rwit h som e HTML / JS. 
More over,ch ange t o tar ge t="self"  will open the href url  in th e sam e f rame as i t w a s c licked bu t th e problemistha t itwil l  clos e th e  c urr e nt se ssio n  and youn ee d t h i ssession ope n n e d ( a tab  wi t h a lo calh ost:port url) tod ownload the da tas. T hou gh, youca n add a non-di stu rb i n g
setProgress(message =_'Calculation in_progress',
   _ __ __  _ detail =_'This may take a_while...',
  __          value=i)

   __ _}_#_end for

   _   }) #_end progress_bar

       counter<<-counter+1_#_needs the <<-_otherwise the value of counter
    _     _  ___   _     _ # is only changed within_the function

     _ download<<-TRUE    _# something to download _ _ 

   _ } #_end if

})_# end function

At_this stage the function makePlots() doesn't_have an output_and isn't called anywhere so it_does_nothing. I therefore_placed_makePlots()_at the_beginning of each_tab_so that_no_matter which tab the user is_on,_once the action button has been clicked_the plots are made_and_saved.
The final piece of_teh puzzle is the download_handler:
output$downloadPlots <- downloadHandler(

   _filename =_function() {_my_filename.zip },
    content = function(file){

   _  fname <- paste(file,"zip",sep=".") 
_   _ zip(fname,new_directory_for_output)_#_zip all files_in_the directory
_     file.rename(fname,file)

 _ _  unlink(new_directory_for_output,recursive = TRUE) #_delete temp directory
 __   download<<-FALSE # hide_download button 
   _}

    )_#_end_download handler

A:

Here is an example_of the html code generated for_a downloadHandler output_:
<a id="downloadData" class="btn shiny-download-link shiny-bound-output" target="_blank" href="session/d832cc1f9218bd9e356572b089628030/download/downloadData?w=">Download</a>

The_target_attribute specifies where to open the_href,_target="_blank" opens it in a new_tab_or_new window.
By default (on many_browser) when you open a new_tab it will focus it, this is what you_want to avoid,_the problem is that you_can't_change_the client default behaviour with some HTML/JS.
Moreover, change to target="self"_will open_the href url_in the same frame as it was clicked but the_problem is that it will close the_current session and you need this session openned (a tab with_a localhost:port url) to download the datas.
Though, you_can add a non-disturbing