Data cleaning action button into Shiny App not working










0















My code is able to upload the csv / text file but not able to clean the data when i press the 'clean' action button. I am not sure what is the issue, when I tried it in both data table and data frame form both does not work. My code's purpose is for the user to:



  1. upload file

  2. press clean to clean the data

  3. download cleaned file

Help would be much appreciated!



Data table form:



library(data.table)
library(DT)
runApp(shinyApp(

ui=(fluidPage(
titlePanel("Clean your data!"),

mainPanel(
fileInput("file", "Upload file"),
actionButton("Go", "Clean!"),

DT::dataTableOutput("df_data_out"),
downloadButton("downloadData","Download")
)
)),
server <- function(input, output)
myData <- reactive(
inFile <- input$file
if (is.null(inFile)) return(NULL)
data <- read.csv(inFile$datapath, header = TRUE)
data <- as.data.table(data)
)
eventReactive(input$Go, splitletter == "I"]
dt3 <- dt2[DocDate <= 20171231 & DocDate >= 20160101]
dt3 <- dt3[AcCurWTaxAmt>0 & HomeWTaxAmt<0,
HomeWTaxAmt:=abs(HomeWTaxAmt)]
dt3 <- dt3[AcCurWTaxAmt<0 & HomeWTaxAmt>0, HomeWTaxAmt:=HomeWTaxAmt*
(-1)]
dt3 <- dt3[AcCurWTaxAmt==0 & HomeWTaxAmt!=0, HomeWTaxAmt:=0]
dt3 <- dt3[AcCurWTaxAmt!=0 & HomeWTaxAmt==0, HomeWTaxAmt:=NA]
dt4 <- na.omit(dt3)
dt4 <- dt4[, AcCrAmt := AcCrIsMinus1 * AcCurWTaxAmt]
dt4 <- dt4[, splitletter:= NULL]
)
output$df_data_out <- DT::renderDataTable(
DT::datatable(myData()))
output$downloadData <- downloadHandler(

filename = function()
paste("data-", Sys.Date(), ".csv", sep="")
,
content = function(file)
write.csv(myData(), file)
)

))


Data frame form:



runApp(shinyApp(
ui=(fluidPage(
titlePanel("Clean your data!"),

mainPanel(
fileInput("file", "Upload file"),
actionButton("Go", "Clean!"),

tableOutput("df_data_out"),
downloadButton("downloadData","Download")
)
)),
server <- function(input, output)
myData <- reactive(
inFile <- input$file
if (is.null(inFile)) return(NULL)
df_data <- read.csv(inFile$datapath, header = TRUE)
df_data <- as.data.frame(df_data)
)
eventReactive(input$Go, dt1$splitletter == "I")
dt3 <- (dt2$DocDate <= 20171231 & dt2$DocDate >= 20160101)
while(dt3$AcCurWTaxAmt>0 & dt$HomeWTaxAmt<0)
dt3$HomeWTaxAmt <- abs(dt3$HomeWTaxAmt)

while(dt3$AcCurWTaxAmt<0 & HomeWTaxAmt>0)
dt3$HomeWTaxAmt <- dt3$HomeWTaxAmt*(-1)

while(dt3$AcCurWTaxAmt==0 & HomeWTaxAmt!=0)
dt3$HomeWTaxAmt <- 0

while(dt3$AcCurWTaxAmt!=0 & HomeWTaxAmt==0)
dt3$HomeWTaxAmt<- NA

dt3 <- na.omit(dt3)
dt3[,AcCrAmt] <- dt3$AcCrIsMinus1 * dt3$HomeWTaxAmt
dt3$splitletter <- NULL
)

output$df_data_out <- renderTable(
myData()
)
output$downloadData <- downloadHandler(

filename = function()
paste("data-", Sys.Date(), ".csv", sep="")
,
content = function(file)
write.csv(myData(), file)
)
))









share|improve this question






















  • cleanedData <- eventReactive(...) then use cleandata() instead of myData()

    – JohnCoene
    Nov 14 '18 at 9:27












  • thank you for your reply! but when i tried that, i obtained these errors: Warning: Error in $: object of type 'closure' is not subsettable 138: substr 137: eventReactiveHandler [#23] 93: cleanedData 92: renderTable [#45] 91: func 78: origRenderFunc 77: output$df_data_out 1: runApp

    – Selina Fang
    Nov 14 '18 at 9:29
















0















My code is able to upload the csv / text file but not able to clean the data when i press the 'clean' action button. I am not sure what is the issue, when I tried it in both data table and data frame form both does not work. My code's purpose is for the user to:



  1. upload file

  2. press clean to clean the data

  3. download cleaned file

Help would be much appreciated!



Data table form:



library(data.table)
library(DT)
runApp(shinyApp(

ui=(fluidPage(
titlePanel("Clean your data!"),

mainPanel(
fileInput("file", "Upload file"),
actionButton("Go", "Clean!"),

DT::dataTableOutput("df_data_out"),
downloadButton("downloadData","Download")
)
)),
server <- function(input, output)
myData <- reactive(
inFile <- input$file
if (is.null(inFile)) return(NULL)
data <- read.csv(inFile$datapath, header = TRUE)
data <- as.data.table(data)
)
eventReactive(input$Go, splitletter == "I"]
dt3 <- dt2[DocDate <= 20171231 & DocDate >= 20160101]
dt3 <- dt3[AcCurWTaxAmt>0 & HomeWTaxAmt<0,
HomeWTaxAmt:=abs(HomeWTaxAmt)]
dt3 <- dt3[AcCurWTaxAmt<0 & HomeWTaxAmt>0, HomeWTaxAmt:=HomeWTaxAmt*
(-1)]
dt3 <- dt3[AcCurWTaxAmt==0 & HomeWTaxAmt!=0, HomeWTaxAmt:=0]
dt3 <- dt3[AcCurWTaxAmt!=0 & HomeWTaxAmt==0, HomeWTaxAmt:=NA]
dt4 <- na.omit(dt3)
dt4 <- dt4[, AcCrAmt := AcCrIsMinus1 * AcCurWTaxAmt]
dt4 <- dt4[, splitletter:= NULL]
)
output$df_data_out <- DT::renderDataTable(
DT::datatable(myData()))
output$downloadData <- downloadHandler(

filename = function()
paste("data-", Sys.Date(), ".csv", sep="")
,
content = function(file)
write.csv(myData(), file)
)

))


Data frame form:



runApp(shinyApp(
ui=(fluidPage(
titlePanel("Clean your data!"),

mainPanel(
fileInput("file", "Upload file"),
actionButton("Go", "Clean!"),

tableOutput("df_data_out"),
downloadButton("downloadData","Download")
)
)),
server <- function(input, output)
myData <- reactive(
inFile <- input$file
if (is.null(inFile)) return(NULL)
df_data <- read.csv(inFile$datapath, header = TRUE)
df_data <- as.data.frame(df_data)
)
eventReactive(input$Go, dt1$splitletter == "I")
dt3 <- (dt2$DocDate <= 20171231 & dt2$DocDate >= 20160101)
while(dt3$AcCurWTaxAmt>0 & dt$HomeWTaxAmt<0)
dt3$HomeWTaxAmt <- abs(dt3$HomeWTaxAmt)

while(dt3$AcCurWTaxAmt<0 & HomeWTaxAmt>0)
dt3$HomeWTaxAmt <- dt3$HomeWTaxAmt*(-1)

while(dt3$AcCurWTaxAmt==0 & HomeWTaxAmt!=0)
dt3$HomeWTaxAmt <- 0

while(dt3$AcCurWTaxAmt!=0 & HomeWTaxAmt==0)
dt3$HomeWTaxAmt<- NA

dt3 <- na.omit(dt3)
dt3[,AcCrAmt] <- dt3$AcCrIsMinus1 * dt3$HomeWTaxAmt
dt3$splitletter <- NULL
)

output$df_data_out <- renderTable(
myData()
)
output$downloadData <- downloadHandler(

filename = function()
paste("data-", Sys.Date(), ".csv", sep="")
,
content = function(file)
write.csv(myData(), file)
)
))









share|improve this question






















  • cleanedData <- eventReactive(...) then use cleandata() instead of myData()

    – JohnCoene
    Nov 14 '18 at 9:27












  • thank you for your reply! but when i tried that, i obtained these errors: Warning: Error in $: object of type 'closure' is not subsettable 138: substr 137: eventReactiveHandler [#23] 93: cleanedData 92: renderTable [#45] 91: func 78: origRenderFunc 77: output$df_data_out 1: runApp

    – Selina Fang
    Nov 14 '18 at 9:29














0












0








0








My code is able to upload the csv / text file but not able to clean the data when i press the 'clean' action button. I am not sure what is the issue, when I tried it in both data table and data frame form both does not work. My code's purpose is for the user to:



  1. upload file

  2. press clean to clean the data

  3. download cleaned file

Help would be much appreciated!



Data table form:



library(data.table)
library(DT)
runApp(shinyApp(

ui=(fluidPage(
titlePanel("Clean your data!"),

mainPanel(
fileInput("file", "Upload file"),
actionButton("Go", "Clean!"),

DT::dataTableOutput("df_data_out"),
downloadButton("downloadData","Download")
)
)),
server <- function(input, output)
myData <- reactive(
inFile <- input$file
if (is.null(inFile)) return(NULL)
data <- read.csv(inFile$datapath, header = TRUE)
data <- as.data.table(data)
)
eventReactive(input$Go, splitletter == "I"]
dt3 <- dt2[DocDate <= 20171231 & DocDate >= 20160101]
dt3 <- dt3[AcCurWTaxAmt>0 & HomeWTaxAmt<0,
HomeWTaxAmt:=abs(HomeWTaxAmt)]
dt3 <- dt3[AcCurWTaxAmt<0 & HomeWTaxAmt>0, HomeWTaxAmt:=HomeWTaxAmt*
(-1)]
dt3 <- dt3[AcCurWTaxAmt==0 & HomeWTaxAmt!=0, HomeWTaxAmt:=0]
dt3 <- dt3[AcCurWTaxAmt!=0 & HomeWTaxAmt==0, HomeWTaxAmt:=NA]
dt4 <- na.omit(dt3)
dt4 <- dt4[, AcCrAmt := AcCrIsMinus1 * AcCurWTaxAmt]
dt4 <- dt4[, splitletter:= NULL]
)
output$df_data_out <- DT::renderDataTable(
DT::datatable(myData()))
output$downloadData <- downloadHandler(

filename = function()
paste("data-", Sys.Date(), ".csv", sep="")
,
content = function(file)
write.csv(myData(), file)
)

))


Data frame form:



runApp(shinyApp(
ui=(fluidPage(
titlePanel("Clean your data!"),

mainPanel(
fileInput("file", "Upload file"),
actionButton("Go", "Clean!"),

tableOutput("df_data_out"),
downloadButton("downloadData","Download")
)
)),
server <- function(input, output)
myData <- reactive(
inFile <- input$file
if (is.null(inFile)) return(NULL)
df_data <- read.csv(inFile$datapath, header = TRUE)
df_data <- as.data.frame(df_data)
)
eventReactive(input$Go, dt1$splitletter == "I")
dt3 <- (dt2$DocDate <= 20171231 & dt2$DocDate >= 20160101)
while(dt3$AcCurWTaxAmt>0 & dt$HomeWTaxAmt<0)
dt3$HomeWTaxAmt <- abs(dt3$HomeWTaxAmt)

while(dt3$AcCurWTaxAmt<0 & HomeWTaxAmt>0)
dt3$HomeWTaxAmt <- dt3$HomeWTaxAmt*(-1)

while(dt3$AcCurWTaxAmt==0 & HomeWTaxAmt!=0)
dt3$HomeWTaxAmt <- 0

while(dt3$AcCurWTaxAmt!=0 & HomeWTaxAmt==0)
dt3$HomeWTaxAmt<- NA

dt3 <- na.omit(dt3)
dt3[,AcCrAmt] <- dt3$AcCrIsMinus1 * dt3$HomeWTaxAmt
dt3$splitletter <- NULL
)

output$df_data_out <- renderTable(
myData()
)
output$downloadData <- downloadHandler(

filename = function()
paste("data-", Sys.Date(), ".csv", sep="")
,
content = function(file)
write.csv(myData(), file)
)
))









share|improve this question














My code is able to upload the csv / text file but not able to clean the data when i press the 'clean' action button. I am not sure what is the issue, when I tried it in both data table and data frame form both does not work. My code's purpose is for the user to:



  1. upload file

  2. press clean to clean the data

  3. download cleaned file

Help would be much appreciated!



Data table form:



library(data.table)
library(DT)
runApp(shinyApp(

ui=(fluidPage(
titlePanel("Clean your data!"),

mainPanel(
fileInput("file", "Upload file"),
actionButton("Go", "Clean!"),

DT::dataTableOutput("df_data_out"),
downloadButton("downloadData","Download")
)
)),
server <- function(input, output)
myData <- reactive(
inFile <- input$file
if (is.null(inFile)) return(NULL)
data <- read.csv(inFile$datapath, header = TRUE)
data <- as.data.table(data)
)
eventReactive(input$Go, splitletter == "I"]
dt3 <- dt2[DocDate <= 20171231 & DocDate >= 20160101]
dt3 <- dt3[AcCurWTaxAmt>0 & HomeWTaxAmt<0,
HomeWTaxAmt:=abs(HomeWTaxAmt)]
dt3 <- dt3[AcCurWTaxAmt<0 & HomeWTaxAmt>0, HomeWTaxAmt:=HomeWTaxAmt*
(-1)]
dt3 <- dt3[AcCurWTaxAmt==0 & HomeWTaxAmt!=0, HomeWTaxAmt:=0]
dt3 <- dt3[AcCurWTaxAmt!=0 & HomeWTaxAmt==0, HomeWTaxAmt:=NA]
dt4 <- na.omit(dt3)
dt4 <- dt4[, AcCrAmt := AcCrIsMinus1 * AcCurWTaxAmt]
dt4 <- dt4[, splitletter:= NULL]
)
output$df_data_out <- DT::renderDataTable(
DT::datatable(myData()))
output$downloadData <- downloadHandler(

filename = function()
paste("data-", Sys.Date(), ".csv", sep="")
,
content = function(file)
write.csv(myData(), file)
)

))


Data frame form:



runApp(shinyApp(
ui=(fluidPage(
titlePanel("Clean your data!"),

mainPanel(
fileInput("file", "Upload file"),
actionButton("Go", "Clean!"),

tableOutput("df_data_out"),
downloadButton("downloadData","Download")
)
)),
server <- function(input, output)
myData <- reactive(
inFile <- input$file
if (is.null(inFile)) return(NULL)
df_data <- read.csv(inFile$datapath, header = TRUE)
df_data <- as.data.frame(df_data)
)
eventReactive(input$Go, dt1$splitletter == "I")
dt3 <- (dt2$DocDate <= 20171231 & dt2$DocDate >= 20160101)
while(dt3$AcCurWTaxAmt>0 & dt$HomeWTaxAmt<0)
dt3$HomeWTaxAmt <- abs(dt3$HomeWTaxAmt)

while(dt3$AcCurWTaxAmt<0 & HomeWTaxAmt>0)
dt3$HomeWTaxAmt <- dt3$HomeWTaxAmt*(-1)

while(dt3$AcCurWTaxAmt==0 & HomeWTaxAmt!=0)
dt3$HomeWTaxAmt <- 0

while(dt3$AcCurWTaxAmt!=0 & HomeWTaxAmt==0)
dt3$HomeWTaxAmt<- NA

dt3 <- na.omit(dt3)
dt3[,AcCrAmt] <- dt3$AcCrIsMinus1 * dt3$HomeWTaxAmt
dt3$splitletter <- NULL
)

output$df_data_out <- renderTable(
myData()
)
output$downloadData <- downloadHandler(

filename = function()
paste("data-", Sys.Date(), ".csv", sep="")
,
content = function(file)
write.csv(myData(), file)
)
))






r shiny






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 9:03









Selina FangSelina Fang

1




1












  • cleanedData <- eventReactive(...) then use cleandata() instead of myData()

    – JohnCoene
    Nov 14 '18 at 9:27












  • thank you for your reply! but when i tried that, i obtained these errors: Warning: Error in $: object of type 'closure' is not subsettable 138: substr 137: eventReactiveHandler [#23] 93: cleanedData 92: renderTable [#45] 91: func 78: origRenderFunc 77: output$df_data_out 1: runApp

    – Selina Fang
    Nov 14 '18 at 9:29


















  • cleanedData <- eventReactive(...) then use cleandata() instead of myData()

    – JohnCoene
    Nov 14 '18 at 9:27












  • thank you for your reply! but when i tried that, i obtained these errors: Warning: Error in $: object of type 'closure' is not subsettable 138: substr 137: eventReactiveHandler [#23] 93: cleanedData 92: renderTable [#45] 91: func 78: origRenderFunc 77: output$df_data_out 1: runApp

    – Selina Fang
    Nov 14 '18 at 9:29

















cleanedData <- eventReactive(...) then use cleandata() instead of myData()

– JohnCoene
Nov 14 '18 at 9:27






cleanedData <- eventReactive(...) then use cleandata() instead of myData()

– JohnCoene
Nov 14 '18 at 9:27














thank you for your reply! but when i tried that, i obtained these errors: Warning: Error in $: object of type 'closure' is not subsettable 138: substr 137: eventReactiveHandler [#23] 93: cleanedData 92: renderTable [#45] 91: func 78: origRenderFunc 77: output$df_data_out 1: runApp

– Selina Fang
Nov 14 '18 at 9:29






thank you for your reply! but when i tried that, i obtained these errors: Warning: Error in $: object of type 'closure' is not subsettable 138: substr 137: eventReactiveHandler [#23] 93: cleanedData 92: renderTable [#45] 91: func 78: origRenderFunc 77: output$df_data_out 1: runApp

– Selina Fang
Nov 14 '18 at 9:29













1 Answer
1






active

oldest

votes


















0














Below is a working example. It's difficult to replicate things with an that takes a CSV as input as we do not know what you chuck in it. Moreover you are referencing columns by name in your eventReactive so I assume you are always passing it a specific CSV.



eventReactive is, well, a reactive function, only it takes also takes an expression that triggers it. As such, it returns a reactive expression just like reactive. You are trying to use eventReactive like observeEvent.



When people click the button eventReactive is triggered and returns a reactive which you do not use. The reactiveexpression object myData remains unchanged. If you do not use the output of eventReactive in any of your outputs (i.e.: output$df_data_out) then the reactive never runs...



Also note that your reactive expressions do not have explicit return.



library(shiny)

ui <- fluidPage(
selectInput("select", "select data", choices = c("cars", "iris")),
actionButton("clean", "Clean data"),
fluidRow(
column(6, tableOutput("original")),
column(6, tableOutput("cleaned"))
)
)

server <- function(input, output, session)

orig_data <- reactive(
if(input$select == "cars")
return(cars)
else
return(iris)
)

cleaned_data <- eventReactive(input$clean,
orig_data() %>%
head(5)
)

output$original <- renderTable(
orig_data()
)

output$cleaned <- renderTable(
cleaned_data()
)



shinyApp(ui, server)





share|improve this answer






















    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%2f53296385%2fdata-cleaning-action-button-into-shiny-app-not-working%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














    Below is a working example. It's difficult to replicate things with an that takes a CSV as input as we do not know what you chuck in it. Moreover you are referencing columns by name in your eventReactive so I assume you are always passing it a specific CSV.



    eventReactive is, well, a reactive function, only it takes also takes an expression that triggers it. As such, it returns a reactive expression just like reactive. You are trying to use eventReactive like observeEvent.



    When people click the button eventReactive is triggered and returns a reactive which you do not use. The reactiveexpression object myData remains unchanged. If you do not use the output of eventReactive in any of your outputs (i.e.: output$df_data_out) then the reactive never runs...



    Also note that your reactive expressions do not have explicit return.



    library(shiny)

    ui <- fluidPage(
    selectInput("select", "select data", choices = c("cars", "iris")),
    actionButton("clean", "Clean data"),
    fluidRow(
    column(6, tableOutput("original")),
    column(6, tableOutput("cleaned"))
    )
    )

    server <- function(input, output, session)

    orig_data <- reactive(
    if(input$select == "cars")
    return(cars)
    else
    return(iris)
    )

    cleaned_data <- eventReactive(input$clean,
    orig_data() %>%
    head(5)
    )

    output$original <- renderTable(
    orig_data()
    )

    output$cleaned <- renderTable(
    cleaned_data()
    )



    shinyApp(ui, server)





    share|improve this answer



























      0














      Below is a working example. It's difficult to replicate things with an that takes a CSV as input as we do not know what you chuck in it. Moreover you are referencing columns by name in your eventReactive so I assume you are always passing it a specific CSV.



      eventReactive is, well, a reactive function, only it takes also takes an expression that triggers it. As such, it returns a reactive expression just like reactive. You are trying to use eventReactive like observeEvent.



      When people click the button eventReactive is triggered and returns a reactive which you do not use. The reactiveexpression object myData remains unchanged. If you do not use the output of eventReactive in any of your outputs (i.e.: output$df_data_out) then the reactive never runs...



      Also note that your reactive expressions do not have explicit return.



      library(shiny)

      ui <- fluidPage(
      selectInput("select", "select data", choices = c("cars", "iris")),
      actionButton("clean", "Clean data"),
      fluidRow(
      column(6, tableOutput("original")),
      column(6, tableOutput("cleaned"))
      )
      )

      server <- function(input, output, session)

      orig_data <- reactive(
      if(input$select == "cars")
      return(cars)
      else
      return(iris)
      )

      cleaned_data <- eventReactive(input$clean,
      orig_data() %>%
      head(5)
      )

      output$original <- renderTable(
      orig_data()
      )

      output$cleaned <- renderTable(
      cleaned_data()
      )



      shinyApp(ui, server)





      share|improve this answer

























        0












        0








        0







        Below is a working example. It's difficult to replicate things with an that takes a CSV as input as we do not know what you chuck in it. Moreover you are referencing columns by name in your eventReactive so I assume you are always passing it a specific CSV.



        eventReactive is, well, a reactive function, only it takes also takes an expression that triggers it. As such, it returns a reactive expression just like reactive. You are trying to use eventReactive like observeEvent.



        When people click the button eventReactive is triggered and returns a reactive which you do not use. The reactiveexpression object myData remains unchanged. If you do not use the output of eventReactive in any of your outputs (i.e.: output$df_data_out) then the reactive never runs...



        Also note that your reactive expressions do not have explicit return.



        library(shiny)

        ui <- fluidPage(
        selectInput("select", "select data", choices = c("cars", "iris")),
        actionButton("clean", "Clean data"),
        fluidRow(
        column(6, tableOutput("original")),
        column(6, tableOutput("cleaned"))
        )
        )

        server <- function(input, output, session)

        orig_data <- reactive(
        if(input$select == "cars")
        return(cars)
        else
        return(iris)
        )

        cleaned_data <- eventReactive(input$clean,
        orig_data() %>%
        head(5)
        )

        output$original <- renderTable(
        orig_data()
        )

        output$cleaned <- renderTable(
        cleaned_data()
        )



        shinyApp(ui, server)





        share|improve this answer













        Below is a working example. It's difficult to replicate things with an that takes a CSV as input as we do not know what you chuck in it. Moreover you are referencing columns by name in your eventReactive so I assume you are always passing it a specific CSV.



        eventReactive is, well, a reactive function, only it takes also takes an expression that triggers it. As such, it returns a reactive expression just like reactive. You are trying to use eventReactive like observeEvent.



        When people click the button eventReactive is triggered and returns a reactive which you do not use. The reactiveexpression object myData remains unchanged. If you do not use the output of eventReactive in any of your outputs (i.e.: output$df_data_out) then the reactive never runs...



        Also note that your reactive expressions do not have explicit return.



        library(shiny)

        ui <- fluidPage(
        selectInput("select", "select data", choices = c("cars", "iris")),
        actionButton("clean", "Clean data"),
        fluidRow(
        column(6, tableOutput("original")),
        column(6, tableOutput("cleaned"))
        )
        )

        server <- function(input, output, session)

        orig_data <- reactive(
        if(input$select == "cars")
        return(cars)
        else
        return(iris)
        )

        cleaned_data <- eventReactive(input$clean,
        orig_data() %>%
        head(5)
        )

        output$original <- renderTable(
        orig_data()
        )

        output$cleaned <- renderTable(
        cleaned_data()
        )



        shinyApp(ui, server)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 9:59









        JohnCoeneJohnCoene

        925617




        925617





























            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%2f53296385%2fdata-cleaning-action-button-into-shiny-app-not-working%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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto