Shiny: Render Outputs when hidden











up vote
0
down vote

favorite












I am trying to render a few outputs in a shiny application that are contained within a shinyjs::hidden section upon the application running rather than once the section is visible.



EDIT: I had the app set up incorrectly in the original example so have changed it.



I want to be able to run the reactive statement before running the final observe to change the UI from the Alpha text to the Beta text and plot. Ideally this would mean in the console would see "Done plotting" before "Observe run".



library(shiny)
library(shinyjs)

ui <- fluidPage(
useShinyjs(),
div(id = "before-content", h3("Aux Text Alpha")),
shinyjs::hidden(
div(
id = "after-content",
h1("Aux Text Beta"),
plotOutput("text")
)
)
)

server <- function( session,input, output) {

in_plot <- reactive({
Sys.sleep(3)
print("Done plotting")
plot(iris)
})

output$text <- renderPlot({
in_plot()
})

observe({
print("Observe run")
hide("before-content")
show("after-content")
})
}

shinyApp(ui, server)


An alternative would be to have a layer over what is classed as the hidden section but am not too sure on how that is accomplished.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am trying to render a few outputs in a shiny application that are contained within a shinyjs::hidden section upon the application running rather than once the section is visible.



    EDIT: I had the app set up incorrectly in the original example so have changed it.



    I want to be able to run the reactive statement before running the final observe to change the UI from the Alpha text to the Beta text and plot. Ideally this would mean in the console would see "Done plotting" before "Observe run".



    library(shiny)
    library(shinyjs)

    ui <- fluidPage(
    useShinyjs(),
    div(id = "before-content", h3("Aux Text Alpha")),
    shinyjs::hidden(
    div(
    id = "after-content",
    h1("Aux Text Beta"),
    plotOutput("text")
    )
    )
    )

    server <- function( session,input, output) {

    in_plot <- reactive({
    Sys.sleep(3)
    print("Done plotting")
    plot(iris)
    })

    output$text <- renderPlot({
    in_plot()
    })

    observe({
    print("Observe run")
    hide("before-content")
    show("after-content")
    })
    }

    shinyApp(ui, server)


    An alternative would be to have a layer over what is classed as the hidden section but am not too sure on how that is accomplished.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to render a few outputs in a shiny application that are contained within a shinyjs::hidden section upon the application running rather than once the section is visible.



      EDIT: I had the app set up incorrectly in the original example so have changed it.



      I want to be able to run the reactive statement before running the final observe to change the UI from the Alpha text to the Beta text and plot. Ideally this would mean in the console would see "Done plotting" before "Observe run".



      library(shiny)
      library(shinyjs)

      ui <- fluidPage(
      useShinyjs(),
      div(id = "before-content", h3("Aux Text Alpha")),
      shinyjs::hidden(
      div(
      id = "after-content",
      h1("Aux Text Beta"),
      plotOutput("text")
      )
      )
      )

      server <- function( session,input, output) {

      in_plot <- reactive({
      Sys.sleep(3)
      print("Done plotting")
      plot(iris)
      })

      output$text <- renderPlot({
      in_plot()
      })

      observe({
      print("Observe run")
      hide("before-content")
      show("after-content")
      })
      }

      shinyApp(ui, server)


      An alternative would be to have a layer over what is classed as the hidden section but am not too sure on how that is accomplished.










      share|improve this question















      I am trying to render a few outputs in a shiny application that are contained within a shinyjs::hidden section upon the application running rather than once the section is visible.



      EDIT: I had the app set up incorrectly in the original example so have changed it.



      I want to be able to run the reactive statement before running the final observe to change the UI from the Alpha text to the Beta text and plot. Ideally this would mean in the console would see "Done plotting" before "Observe run".



      library(shiny)
      library(shinyjs)

      ui <- fluidPage(
      useShinyjs(),
      div(id = "before-content", h3("Aux Text Alpha")),
      shinyjs::hidden(
      div(
      id = "after-content",
      h1("Aux Text Beta"),
      plotOutput("text")
      )
      )
      )

      server <- function( session,input, output) {

      in_plot <- reactive({
      Sys.sleep(3)
      print("Done plotting")
      plot(iris)
      })

      output$text <- renderPlot({
      in_plot()
      })

      observe({
      print("Observe run")
      hide("before-content")
      show("after-content")
      })
      }

      shinyApp(ui, server)


      An alternative would be to have a layer over what is classed as the hidden section but am not too sure on how that is accomplished.







      r shiny shinyjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 15:44

























      asked Nov 7 at 12:24









      Ashley Baldry

      13511




      13511
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You can hide it in the reactive, like so:



          library(shiny)
          library(shinyjs)

          ui <- fluidPage(
          useShinyjs(),
          actionButton("button", "Click me"),
          plotOutput("text")
          )

          server <- function( session,input, output) {

          in_plot <- reactive({
          hide("text")
          Sys.sleep(3)
          print("Done plotting")
          plot(iris)
          })

          output$text <- renderPlot({
          in_plot()
          })

          observeEvent(input$button, {
          show("text")
          })
          }

          shinyApp(ui, server)





          share|improve this answer





















          • Apologies, I've realised that I have set up the example slightly wrong. Will update and hopefully makes it clearer. Thanks for the suggestion though!
            – Ashley Baldry
            Nov 7 at 15:37











          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',
          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%2f53189429%2fshiny-render-outputs-when-hidden%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








          up vote
          0
          down vote













          You can hide it in the reactive, like so:



          library(shiny)
          library(shinyjs)

          ui <- fluidPage(
          useShinyjs(),
          actionButton("button", "Click me"),
          plotOutput("text")
          )

          server <- function( session,input, output) {

          in_plot <- reactive({
          hide("text")
          Sys.sleep(3)
          print("Done plotting")
          plot(iris)
          })

          output$text <- renderPlot({
          in_plot()
          })

          observeEvent(input$button, {
          show("text")
          })
          }

          shinyApp(ui, server)





          share|improve this answer





















          • Apologies, I've realised that I have set up the example slightly wrong. Will update and hopefully makes it clearer. Thanks for the suggestion though!
            – Ashley Baldry
            Nov 7 at 15:37















          up vote
          0
          down vote













          You can hide it in the reactive, like so:



          library(shiny)
          library(shinyjs)

          ui <- fluidPage(
          useShinyjs(),
          actionButton("button", "Click me"),
          plotOutput("text")
          )

          server <- function( session,input, output) {

          in_plot <- reactive({
          hide("text")
          Sys.sleep(3)
          print("Done plotting")
          plot(iris)
          })

          output$text <- renderPlot({
          in_plot()
          })

          observeEvent(input$button, {
          show("text")
          })
          }

          shinyApp(ui, server)





          share|improve this answer





















          • Apologies, I've realised that I have set up the example slightly wrong. Will update and hopefully makes it clearer. Thanks for the suggestion though!
            – Ashley Baldry
            Nov 7 at 15:37













          up vote
          0
          down vote










          up vote
          0
          down vote









          You can hide it in the reactive, like so:



          library(shiny)
          library(shinyjs)

          ui <- fluidPage(
          useShinyjs(),
          actionButton("button", "Click me"),
          plotOutput("text")
          )

          server <- function( session,input, output) {

          in_plot <- reactive({
          hide("text")
          Sys.sleep(3)
          print("Done plotting")
          plot(iris)
          })

          output$text <- renderPlot({
          in_plot()
          })

          observeEvent(input$button, {
          show("text")
          })
          }

          shinyApp(ui, server)





          share|improve this answer












          You can hide it in the reactive, like so:



          library(shiny)
          library(shinyjs)

          ui <- fluidPage(
          useShinyjs(),
          actionButton("button", "Click me"),
          plotOutput("text")
          )

          server <- function( session,input, output) {

          in_plot <- reactive({
          hide("text")
          Sys.sleep(3)
          print("Done plotting")
          plot(iris)
          })

          output$text <- renderPlot({
          in_plot()
          })

          observeEvent(input$button, {
          show("text")
          })
          }

          shinyApp(ui, server)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 12:35









          Pork Chop

          13.5k12340




          13.5k12340












          • Apologies, I've realised that I have set up the example slightly wrong. Will update and hopefully makes it clearer. Thanks for the suggestion though!
            – Ashley Baldry
            Nov 7 at 15:37


















          • Apologies, I've realised that I have set up the example slightly wrong. Will update and hopefully makes it clearer. Thanks for the suggestion though!
            – Ashley Baldry
            Nov 7 at 15:37
















          Apologies, I've realised that I have set up the example slightly wrong. Will update and hopefully makes it clearer. Thanks for the suggestion though!
          – Ashley Baldry
          Nov 7 at 15:37




          Apologies, I've realised that I have set up the example slightly wrong. Will update and hopefully makes it clearer. Thanks for the suggestion though!
          – Ashley Baldry
          Nov 7 at 15:37


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189429%2fshiny-render-outputs-when-hidden%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







          這個網誌中的熱門文章

          Hercules Kyvelos

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud