how to save miniUI output [variable and dataframe]


#1

...Hi

I write a miniUI to create a dataframe.

how to save the dataframe output after I close the miniUI(shiny Gadget UI) ?

My purpose is create a new dataframe by filter a old dataframe using miniUI

for example , how can I call the [output$table] after i close miniUI(shiny Gadget UI) ?

  output$table <- renderTable({
    select_var001=input$select
    where_var001=where_var001=data.frame(left=c('country','gdpPercap'),fomulate=c('=','>'),right=c('"Afghanistan"','1'))
    sql=make_sql(select_var001,where_var001)
    data=sqldf(sql)
 })

https://shiny.rstudio.com/articles/gadget-ui.html

Thank you
T


#2

There are two things you will need to do:

  1. Add an observer that listens for input$done and calls stopApp(). The value that is passed to stopApp() will be returned when the application exits
  2. Add a reactive that returns the data you want, and use that in both output$table <- renderTable() and the stopApp().

For example:

server <- function(input, output, session) {
  mydata <- reactive({
    select_var001 <- input$select
    where_var001 <- 
 data.frame(left=c('country','gdpPercap'),fomulate=c('=','>'),right=c('"Afghanistan"','1'))
    sql <- make_sql(select_var001, where_var001)
    sqldf(sql)
  })

  output$table <- renderTable({
    mytable()
  })

   # Return mydata() when the user clicks on Done
   observeEvent(input$done, {
    stopApp(mydata())
  })
}

See the simple example here:
https://shiny.rstudio.com/articles/gadgets.html#writing-shiny-gadgets


#3

Thank you so many for answering my question. the mytable() should be mydata()

And it did return the data frame . But How can I assign the dataframe to a variable instead of just print it out ?


#4

You just need to assign it when you invoke the app, as in:

x <- myGadget()

#5

solved! wrap it as a function as myGadget() and then assign to x

thanks a lot.


#6

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