M Rob
M Rob

Reputation: 31

Action button shiny

I want to execute action button in Shiny. I have UI, Server and helpercode (which has all the functions). I want to go to the function in helpercode only if the button is pressed. Following is the code:

UI -

tabPanel("Conversion", 
                           box(status = "primary", solidHeader = TRUE, 
                             collapsible = TRUE,

 shinyUI(fluidPage( 

 fluidRow(

 column(width = 6, textInput("selectnew", "Select :",value="Split"),

 actionButton("gobutton", "Start")

  ), 

  column(width = 12, offset = 0, h5(""), DT::dataTableOutput("tablenew"))

Server -

output$tablenew = DT :: renderDataTable({
    function_new(input$selectnew)
  })

Helpercode -

function_new ()

I have tried observeEvent and EventReactive but it is not working.

Upvotes: 1

Views: 139

Answers (1)

Pork Chop
Pork Chop

Reputation: 29407

Something like this should be enough for you to go

library(shiny)
library(DT)

function_new <- function(x){
  as.data.frame(x)
}

ui <- fluidPage(

  fluidRow(
    column(width = 6, textInput("selectnew", "Select :",value="Split"),
           actionButton("gobutton", "Start")),
    column(width = 12, offset = 0, h5(""),dataTableOutput("tablenew"))
  )
)
server <- function(input, output, session) {

  data <- eventReactive(input$gobutton,{
    function_new(input$selectnew)
  })

  output$tablenew <- renderDataTable({
    data()
  })
}

shinyApp(ui, server)

Upvotes: 2

Related Questions