0

I would ask. Does Shiny do like always-refreshing the code after input ? First I code this in ui :

 box( ##title="Quality Attributes",
               selectInput("att_ViewChart", width = '100%',label="Quality Attributes",
                          ##multiple = TRUE, 
                           choices=list(
                             "-",
                             "Suitability",
                             "Security",

                           )
               )
          ),
 dataTableOutput("tabelstatus")

Then I code this in server :

 server = function(input, output) {
 withProgress(message = "AAAAA",{
      DateStatus_Sui<-c(1,2,3,4,NA,5,6,NA,7)
      TimeStatus_Sui<-c(11,22,33,44,NA,55,66,NA,88)
      status_Sui<-c(11,22,44,55,66,77,88)
      jumlah<-7
    })
  if(input$att_ViewChart=="Suitability"){
        Date<-DateStatus_Sui[!is.na(DateStatus_Sui)]
        Time<-TimeStatus_Sui[!is.na(TimeStatus_Sui)]
        Status<-status_Sui
        Observation<-1:jumlah
        #output

        tabelstatus<-data.frame(Observation,Date,Time,Status)
        output$tabelstatus<-renderDataTable(tabelstatus)
}

I hope when I run the app. Shiny will process the code (shown by progress bar 'AAAAA') And after that, if I choose Suitability it will do a little more process and then show the table . But I found that the progress bar appears again. Seems to me it re-runs the code from the beginning. How to fix this? Thank you

Elbert
  • 516
  • 1
  • 5
  • 15
  • Can you post the whole of your `server.R`? or at least make a complete reproducible example? – SymbolixAU May 09 '16 at 05:08
  • @Symbolix it is reproducible code. the real one is much more complex. isnt it working? – Elbert May 09 '16 at 05:11
  • "reproducible" means that I can simply copy & paste your code into my R environment and it will work. I can't do that with your code. Without seeing the whole of your `server.R` it's hard to diagnose your issue. I would guess you don't have your `if(input$att_ViewChart...)` inside a `reactive()` expression. Either that or you need to `isolate( )` the `if(input$...)` condition. – SymbolixAU May 09 '16 at 05:15
  • @symbolix. is it reproducible yet? I just add the server – Elbert May 09 '16 at 05:36
  • 1
    You can check for yourself if it is reproducible (it is not): start a new R session, create new files with just the content you provided above, and try to run the shiny app. If you haven't already, I suggest reading both [mcve](http://stackoverflow.com/help/mcve) and [reproducible examples](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – r2evans May 09 '16 at 05:39

1 Answers1

2

In the abscence of a fully reproducible example, I'm guessing this is what you're trying to do (i.e, make the table reactive according to your input$att_ViewChart):

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
        box( selectInput("att_ViewChart", width = '100%',label="Quality Attributes",
                                    choices=c("-","Suitability","Security"))),
        dataTableOutput("tablestatus")
    )
)

server = function(input, output) {

    withProgress(message = "AAAAA",{
        DateStatus_Sui<-c(1,2,3,4,NA,5,6,NA,7)
        TimeStatus_Sui<-c(11,22,33,44,NA,55,66,NA,88)
        status_Sui<-c(11,22,44,55,66,77,88)
        jumlah<-7
    })

    ## make your table reactive on `input$att_ViewChart`
    output$tablestatus <- renderDataTable({

        if(input$att_ViewChart=="Suitability"){

            Date<-DateStatus_Sui[!is.na(DateStatus_Sui)]
            Time<-TimeStatus_Sui[!is.na(TimeStatus_Sui)]
            Status<-status_Sui
            Observation<-1:jumlah

            tablestatus <- data.frame(Observation,Date,Time,Status)
        }else{
            tablestatus <-data.frame()
        }
        return(tablestatus)
    })
}

shinyApp(ui = ui, server = server)
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
  • yeah it is. But when I choose 'Suitability' , the progress bar appears again like doing all the code from the beginning – Elbert May 09 '16 at 05:55
  • @Elbert the progress bar doens't get reloaded - are you sure you've copied my code exactly? – SymbolixAU May 09 '16 at 05:57
  • I copy it to the real one. And the progress bar reloaded. I make it in a new file. it doesnt. I will check other parts then. btw, if there is an upload file fiture before those code, does it affect anything? – Elbert May 09 '16 at 06:02
  • @Elbert - hard to say - it depends on where you put the upload file feature, how you call it, etc. – SymbolixAU May 09 '16 at 06:07