Convert Shiny App R code to RMarkdown Shiny App code with Action Buttons

A question posted at

Can you help please to rewrite the following code (from Shiny - Using Action Buttons) into RMarkdown?

# Codes from https://shiny.rstudio.com/articles/action-buttons.html

library(shiny)

ui <- fluidPage(
  # Pattern 1 - Command 
  tags$head(tags$script(src = "message-handler.js")),
  actionButton("do", "Click Me"),
  hr(),
  
  # Pattern 2 - Delay reactions
  actionButton("go", "Go"),
  numericInput("n", "n", 50),
  plotOutput("plot2"), 
)
  
server <- function(input, output, session) {
  
  # Pattern 1 - Command
  observeEvent(input$do,  {
    session$sendCustomMessage(type = 'testmessage',
                              message = 'Thank you for clicking')
  } )
  
  # Pattern 2 - Delay reactions
  randomVals <- eventReactive(input$go, {
    runif(input$n)
  })
  output$plot2 <- renderPlot({
    hist(randomVals())
  })
 }

shinyApp(ui, server)
---
title: "button_example"
output: flexdashboard::flex_dashboard
runtime: shiny
---

Column {.sidebar}
-----------------------------------------------------------------------
  

```{r}

actionButton("first_button","push me")
```

Column
-----------------------------------------------------------------------
  ```{r}
renderText({
  paste0("Button was pressed ", input$first_button, " times" )
})
```

Got it for second pattern.

---
title: "Use of Action button in RMarkdown" 
output: html_document
runtime: shiny
---


```{r}
# Codes from https://shiny.rstudio.com/articles/action-buttons.html

# Pattern 2 - Delay reactions
actionButton("go", "Go")
numericInput("n", "n", 50)
# plotOutput("plot2") 
hr()

# THIS IS WHAT ONE NEEDS TO WRITE HERE:

# Pattern 2 - Delay reactions
randomVals <- eventReactive(input$go, {
  runif(input$n)
})
# output$plot2 <- 
renderPlot({
  hist(randomVals())
})

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.