How do I animate my R Shiny plot's output based on the increments of slider input value?R Shiny animated slider with renderUIShiny slider on logarithmic scaleShiny Changing Slider Animation SpeedWorking with reactiveValues and ggplot in shinyR Shiny input slider range valuesR shiny slider incrementsShiny nearPoints() with slider inputStored Input values in shiny widgets?If Statement in Shiny based on values in reactiveHow to set an initial value for two dependent input values (Slider and Numeric) in shiny?

"Best practices" for formulating MIPs

Auto replacement of characters

Was Wolfgang Unzicker the last Amateur GM?

Do human thoughts interact with matter?

Turing Machines: What is the difference between recognizing, deciding, total, accepting, rejecting?

How did sloshing prevent the Apollo Service Module from moving safely away from the Command Module and how was this fixed?

Show that there are infinitely more problems than we will ever be able to compute

What do you call the motor that fuels the movement of a robotic arm?

Why is quantum gravity non-renormalizable?

Birthday girl's casino game

3D nonogram – What's going on?

How can I know (without going to the station) if RATP is offering the Anti Pollution tickets?

Why did my leaking pool light trip the circuit breaker, but not the GFCI?

Do I need to be legally qualified to install a Hive smart thermostat?

Sleepy tired vs physically tired

Is my background sufficient to start Quantum Computing

Are the plates of a battery really charged?

Language Selector

Which high-degree derivatives play an essential role?

SQL Server error 242 with ANSI datetime

Should I cross-validate metrics that were not optimised?

How frequently do Russian people still refer to others by their patronymic (отчество)?

What is a "tittering order"?

Does the North Korea Kim Jong Un have an heir?



How do I animate my R Shiny plot's output based on the increments of slider input value?


R Shiny animated slider with renderUIShiny slider on logarithmic scaleShiny Changing Slider Animation SpeedWorking with reactiveValues and ggplot in shinyR Shiny input slider range valuesR shiny slider incrementsShiny nearPoints() with slider inputStored Input values in shiny widgets?If Statement in Shiny based on values in reactiveHow to set an initial value for two dependent input values (Slider and Numeric) in shiny?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I've looked through R Shiny tutorials and stackoverflow for answers related to my query. I usually wait for 3-4 days to solve a coding problem before I attempt to post.



I have an animated slider in my UI that loops through time interval in a column (column a) . I'm trying to produce an animated line plot that plots y values of another column (column b), corresponding to the nrow() of that time interval. The slider works perfectly, but I haven't been able to plot the output.



I mightve missed some concepts related to reactivity in Shiny app. Appreciate any guidance I can get related to my query. I'll be happy to post more info if needed.



a <- c(0,1,2,3,4,5,6) 
b <- c(50,100,40,30,20,80)

mydata <- cbind(a,b)
mydata <- as.data.frame(mydata())

ui <- fluidPage (

headerPanel("basic app"),

sidebarPanel(

sliderInput("slider",
label = "Time elapsed",
min = 0,
max = nrow(mydata()),
value = 1, step = 1,
animate =
animationOptions(interval = 200, loop = TRUE))
),
mainPanel(
plotlyOutput("plot")
)
)

server <- function(input, output)
sliderValues <- reactive(
data.frame(
Name = "slider",
Value = input$slider)
)
output$plot <- renderPlot(
x<- as.numeric(input$slider)
y <- as.numeric(b[x])
ggplot(mydata,aes_string(x,y))+ geom_line()
)






Just as a demo, I wanted the animated plot to come out like this, but in correspondance to UI slider values :



library(gganimate)
library(ggplot2)
fake <- c(1,10)
goods <- c(11,20)
fakegoods <- cbind(fake,goods)
fakegoods <- data.frame(fakegoods)
ggplot(fakegoods, aes(fake, goods)) + geom_line() + transition_reveal(1, fake)










share|improve this question






























    0















    I've looked through R Shiny tutorials and stackoverflow for answers related to my query. I usually wait for 3-4 days to solve a coding problem before I attempt to post.



    I have an animated slider in my UI that loops through time interval in a column (column a) . I'm trying to produce an animated line plot that plots y values of another column (column b), corresponding to the nrow() of that time interval. The slider works perfectly, but I haven't been able to plot the output.



    I mightve missed some concepts related to reactivity in Shiny app. Appreciate any guidance I can get related to my query. I'll be happy to post more info if needed.



    a <- c(0,1,2,3,4,5,6) 
    b <- c(50,100,40,30,20,80)

    mydata <- cbind(a,b)
    mydata <- as.data.frame(mydata())

    ui <- fluidPage (

    headerPanel("basic app"),

    sidebarPanel(

    sliderInput("slider",
    label = "Time elapsed",
    min = 0,
    max = nrow(mydata()),
    value = 1, step = 1,
    animate =
    animationOptions(interval = 200, loop = TRUE))
    ),
    mainPanel(
    plotlyOutput("plot")
    )
    )

    server <- function(input, output)
    sliderValues <- reactive(
    data.frame(
    Name = "slider",
    Value = input$slider)
    )
    output$plot <- renderPlot(
    x<- as.numeric(input$slider)
    y <- as.numeric(b[x])
    ggplot(mydata,aes_string(x,y))+ geom_line()
    )






    Just as a demo, I wanted the animated plot to come out like this, but in correspondance to UI slider values :



    library(gganimate)
    library(ggplot2)
    fake <- c(1,10)
    goods <- c(11,20)
    fakegoods <- cbind(fake,goods)
    fakegoods <- data.frame(fakegoods)
    ggplot(fakegoods, aes(fake, goods)) + geom_line() + transition_reveal(1, fake)










    share|improve this question


























      0












      0








      0








      I've looked through R Shiny tutorials and stackoverflow for answers related to my query. I usually wait for 3-4 days to solve a coding problem before I attempt to post.



      I have an animated slider in my UI that loops through time interval in a column (column a) . I'm trying to produce an animated line plot that plots y values of another column (column b), corresponding to the nrow() of that time interval. The slider works perfectly, but I haven't been able to plot the output.



      I mightve missed some concepts related to reactivity in Shiny app. Appreciate any guidance I can get related to my query. I'll be happy to post more info if needed.



      a <- c(0,1,2,3,4,5,6) 
      b <- c(50,100,40,30,20,80)

      mydata <- cbind(a,b)
      mydata <- as.data.frame(mydata())

      ui <- fluidPage (

      headerPanel("basic app"),

      sidebarPanel(

      sliderInput("slider",
      label = "Time elapsed",
      min = 0,
      max = nrow(mydata()),
      value = 1, step = 1,
      animate =
      animationOptions(interval = 200, loop = TRUE))
      ),
      mainPanel(
      plotlyOutput("plot")
      )
      )

      server <- function(input, output)
      sliderValues <- reactive(
      data.frame(
      Name = "slider",
      Value = input$slider)
      )
      output$plot <- renderPlot(
      x<- as.numeric(input$slider)
      y <- as.numeric(b[x])
      ggplot(mydata,aes_string(x,y))+ geom_line()
      )






      Just as a demo, I wanted the animated plot to come out like this, but in correspondance to UI slider values :



      library(gganimate)
      library(ggplot2)
      fake <- c(1,10)
      goods <- c(11,20)
      fakegoods <- cbind(fake,goods)
      fakegoods <- data.frame(fakegoods)
      ggplot(fakegoods, aes(fake, goods)) + geom_line() + transition_reveal(1, fake)










      share|improve this question
















      I've looked through R Shiny tutorials and stackoverflow for answers related to my query. I usually wait for 3-4 days to solve a coding problem before I attempt to post.



      I have an animated slider in my UI that loops through time interval in a column (column a) . I'm trying to produce an animated line plot that plots y values of another column (column b), corresponding to the nrow() of that time interval. The slider works perfectly, but I haven't been able to plot the output.



      I mightve missed some concepts related to reactivity in Shiny app. Appreciate any guidance I can get related to my query. I'll be happy to post more info if needed.



      a <- c(0,1,2,3,4,5,6) 
      b <- c(50,100,40,30,20,80)

      mydata <- cbind(a,b)
      mydata <- as.data.frame(mydata())

      ui <- fluidPage (

      headerPanel("basic app"),

      sidebarPanel(

      sliderInput("slider",
      label = "Time elapsed",
      min = 0,
      max = nrow(mydata()),
      value = 1, step = 1,
      animate =
      animationOptions(interval = 200, loop = TRUE))
      ),
      mainPanel(
      plotlyOutput("plot")
      )
      )

      server <- function(input, output)
      sliderValues <- reactive(
      data.frame(
      Name = "slider",
      Value = input$slider)
      )
      output$plot <- renderPlot(
      x<- as.numeric(input$slider)
      y <- as.numeric(b[x])
      ggplot(mydata,aes_string(x,y))+ geom_line()
      )






      Just as a demo, I wanted the animated plot to come out like this, but in correspondance to UI slider values :



      library(gganimate)
      library(ggplot2)
      fake <- c(1,10)
      goods <- c(11,20)
      fakegoods <- cbind(fake,goods)
      fakegoods <- data.frame(fakegoods)
      ggplot(fakegoods, aes(fake, goods)) + geom_line() + transition_reveal(1, fake)







      r ggplot2 shiny slider shiny-reactivity






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 19:04









      Axeman

      20.2k5 gold badges45 silver badges61 bronze badges




      20.2k5 gold badges45 silver badges61 bronze badges










      asked Mar 25 at 17:47









      flustercludgeflustercludge

      124 bronze badges




      124 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Does this accomplish what you are looking for? Note that I removed the first element, 0, from vector a as your original example had more elements in a than b, and in order for them to be cbind together they must be the same length.



          library(ggplot2)
          library(shiny)

          a <- c(1,2,3,4,5,6)
          b <- c(50,100,40,30,20,80)

          mydata <- cbind(a,b)
          mydata <- as.data.frame(mydata)

          ui <- fluidPage (

          headerPanel("basic app"),

          sidebarPanel(

          sliderInput("slider",
          label = "Time elapsed",
          min = min(mydata$a),
          max = max(mydata$a),
          value = min(mydata$a), step = 1,
          animate =
          animationOptions(interval = 200, loop = TRUE))
          ),
          mainPanel(
          plotOutput("plot")
          )
          )

          server <- function(input, output)
          output$plot <- renderPlot(
          plotdata <- mydata[1:which(input$slider==mydata$a),]
          p <- ggplot(plotdata,aes(x = a,y = b))

          if(nrow(plotdata)==1)
          p + geom_point()
          else
          p + geom_line()


          )






          share|improve this answer

























          • Thank you ! I tried it and I got "Warning: Error in :: argument of length 0", which means I'll have to get rid of the NA values first?

            – flustercludge
            Mar 26 at 1:55











          • where do you have NA values? There were no NA values mentioned in your OP. Please make sure your question is complete and contains all information.

            – Wil
            Mar 26 at 12:34












          • Apologies for that, I'll make my info more complete next time ! Thank you for the input, my code finally works now !

            – flustercludge
            Mar 26 at 20:46











          • I'm glad to hear it works. If my answer helped, please accept it.

            – Wil
            Mar 26 at 20:53










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55343756%2fhow-do-i-animate-my-r-shiny-plots-output-based-on-the-increments-of-slider-inpu%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Does this accomplish what you are looking for? Note that I removed the first element, 0, from vector a as your original example had more elements in a than b, and in order for them to be cbind together they must be the same length.



          library(ggplot2)
          library(shiny)

          a <- c(1,2,3,4,5,6)
          b <- c(50,100,40,30,20,80)

          mydata <- cbind(a,b)
          mydata <- as.data.frame(mydata)

          ui <- fluidPage (

          headerPanel("basic app"),

          sidebarPanel(

          sliderInput("slider",
          label = "Time elapsed",
          min = min(mydata$a),
          max = max(mydata$a),
          value = min(mydata$a), step = 1,
          animate =
          animationOptions(interval = 200, loop = TRUE))
          ),
          mainPanel(
          plotOutput("plot")
          )
          )

          server <- function(input, output)
          output$plot <- renderPlot(
          plotdata <- mydata[1:which(input$slider==mydata$a),]
          p <- ggplot(plotdata,aes(x = a,y = b))

          if(nrow(plotdata)==1)
          p + geom_point()
          else
          p + geom_line()


          )






          share|improve this answer

























          • Thank you ! I tried it and I got "Warning: Error in :: argument of length 0", which means I'll have to get rid of the NA values first?

            – flustercludge
            Mar 26 at 1:55











          • where do you have NA values? There were no NA values mentioned in your OP. Please make sure your question is complete and contains all information.

            – Wil
            Mar 26 at 12:34












          • Apologies for that, I'll make my info more complete next time ! Thank you for the input, my code finally works now !

            – flustercludge
            Mar 26 at 20:46











          • I'm glad to hear it works. If my answer helped, please accept it.

            – Wil
            Mar 26 at 20:53















          0














          Does this accomplish what you are looking for? Note that I removed the first element, 0, from vector a as your original example had more elements in a than b, and in order for them to be cbind together they must be the same length.



          library(ggplot2)
          library(shiny)

          a <- c(1,2,3,4,5,6)
          b <- c(50,100,40,30,20,80)

          mydata <- cbind(a,b)
          mydata <- as.data.frame(mydata)

          ui <- fluidPage (

          headerPanel("basic app"),

          sidebarPanel(

          sliderInput("slider",
          label = "Time elapsed",
          min = min(mydata$a),
          max = max(mydata$a),
          value = min(mydata$a), step = 1,
          animate =
          animationOptions(interval = 200, loop = TRUE))
          ),
          mainPanel(
          plotOutput("plot")
          )
          )

          server <- function(input, output)
          output$plot <- renderPlot(
          plotdata <- mydata[1:which(input$slider==mydata$a),]
          p <- ggplot(plotdata,aes(x = a,y = b))

          if(nrow(plotdata)==1)
          p + geom_point()
          else
          p + geom_line()


          )






          share|improve this answer

























          • Thank you ! I tried it and I got "Warning: Error in :: argument of length 0", which means I'll have to get rid of the NA values first?

            – flustercludge
            Mar 26 at 1:55











          • where do you have NA values? There were no NA values mentioned in your OP. Please make sure your question is complete and contains all information.

            – Wil
            Mar 26 at 12:34












          • Apologies for that, I'll make my info more complete next time ! Thank you for the input, my code finally works now !

            – flustercludge
            Mar 26 at 20:46











          • I'm glad to hear it works. If my answer helped, please accept it.

            – Wil
            Mar 26 at 20:53













          0












          0








          0







          Does this accomplish what you are looking for? Note that I removed the first element, 0, from vector a as your original example had more elements in a than b, and in order for them to be cbind together they must be the same length.



          library(ggplot2)
          library(shiny)

          a <- c(1,2,3,4,5,6)
          b <- c(50,100,40,30,20,80)

          mydata <- cbind(a,b)
          mydata <- as.data.frame(mydata)

          ui <- fluidPage (

          headerPanel("basic app"),

          sidebarPanel(

          sliderInput("slider",
          label = "Time elapsed",
          min = min(mydata$a),
          max = max(mydata$a),
          value = min(mydata$a), step = 1,
          animate =
          animationOptions(interval = 200, loop = TRUE))
          ),
          mainPanel(
          plotOutput("plot")
          )
          )

          server <- function(input, output)
          output$plot <- renderPlot(
          plotdata <- mydata[1:which(input$slider==mydata$a),]
          p <- ggplot(plotdata,aes(x = a,y = b))

          if(nrow(plotdata)==1)
          p + geom_point()
          else
          p + geom_line()


          )






          share|improve this answer















          Does this accomplish what you are looking for? Note that I removed the first element, 0, from vector a as your original example had more elements in a than b, and in order for them to be cbind together they must be the same length.



          library(ggplot2)
          library(shiny)

          a <- c(1,2,3,4,5,6)
          b <- c(50,100,40,30,20,80)

          mydata <- cbind(a,b)
          mydata <- as.data.frame(mydata)

          ui <- fluidPage (

          headerPanel("basic app"),

          sidebarPanel(

          sliderInput("slider",
          label = "Time elapsed",
          min = min(mydata$a),
          max = max(mydata$a),
          value = min(mydata$a), step = 1,
          animate =
          animationOptions(interval = 200, loop = TRUE))
          ),
          mainPanel(
          plotOutput("plot")
          )
          )

          server <- function(input, output)
          output$plot <- renderPlot(
          plotdata <- mydata[1:which(input$slider==mydata$a),]
          p <- ggplot(plotdata,aes(x = a,y = b))

          if(nrow(plotdata)==1)
          p + geom_point()
          else
          p + geom_line()


          )







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 26 at 12:34

























          answered Mar 25 at 19:30









          WilWil

          1,7711 gold badge2 silver badges17 bronze badges




          1,7711 gold badge2 silver badges17 bronze badges












          • Thank you ! I tried it and I got "Warning: Error in :: argument of length 0", which means I'll have to get rid of the NA values first?

            – flustercludge
            Mar 26 at 1:55











          • where do you have NA values? There were no NA values mentioned in your OP. Please make sure your question is complete and contains all information.

            – Wil
            Mar 26 at 12:34












          • Apologies for that, I'll make my info more complete next time ! Thank you for the input, my code finally works now !

            – flustercludge
            Mar 26 at 20:46











          • I'm glad to hear it works. If my answer helped, please accept it.

            – Wil
            Mar 26 at 20:53

















          • Thank you ! I tried it and I got "Warning: Error in :: argument of length 0", which means I'll have to get rid of the NA values first?

            – flustercludge
            Mar 26 at 1:55











          • where do you have NA values? There were no NA values mentioned in your OP. Please make sure your question is complete and contains all information.

            – Wil
            Mar 26 at 12:34












          • Apologies for that, I'll make my info more complete next time ! Thank you for the input, my code finally works now !

            – flustercludge
            Mar 26 at 20:46











          • I'm glad to hear it works. If my answer helped, please accept it.

            – Wil
            Mar 26 at 20:53
















          Thank you ! I tried it and I got "Warning: Error in :: argument of length 0", which means I'll have to get rid of the NA values first?

          – flustercludge
          Mar 26 at 1:55





          Thank you ! I tried it and I got "Warning: Error in :: argument of length 0", which means I'll have to get rid of the NA values first?

          – flustercludge
          Mar 26 at 1:55













          where do you have NA values? There were no NA values mentioned in your OP. Please make sure your question is complete and contains all information.

          – Wil
          Mar 26 at 12:34






          where do you have NA values? There were no NA values mentioned in your OP. Please make sure your question is complete and contains all information.

          – Wil
          Mar 26 at 12:34














          Apologies for that, I'll make my info more complete next time ! Thank you for the input, my code finally works now !

          – flustercludge
          Mar 26 at 20:46





          Apologies for that, I'll make my info more complete next time ! Thank you for the input, my code finally works now !

          – flustercludge
          Mar 26 at 20:46













          I'm glad to hear it works. If my answer helped, please accept it.

          – Wil
          Mar 26 at 20:53





          I'm glad to hear it works. If my answer helped, please accept it.

          – Wil
          Mar 26 at 20:53








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55343756%2fhow-do-i-animate-my-r-shiny-plots-output-based-on-the-increments-of-slider-inpu%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현