How the get a list of reactive output elements?
what works without problems is: observe(print(reactiveValuesToList(input)) )
what doesn't work for reasons i don't understand is: observe( print(reactiveValuesToList(output)) )
For a large complex app, I am writing a smart code that in part A saves all reactivevalues and all inputs as rds
files with saveRDS
my reactivevalues
are build this way; values <- reactivevalues()
Part B loads all these values with the use of readRDS. reactive values$x
are reassigned and input$x are updated through for instance updateTextinput(session, inputID, value)
, which for some weird reason also works for selectInput
elements, but that is not relevant for the problem I face.
My app also contains renderUI
elements and renderText
elements
to update these elements, I need to set the option :
outputOptions(output, x, suspendWhenHidden = FALSE)}
where x
is the name of the element. I have however dozens of these elements, and want to apply the setting of this suspendWhenHidden
option to a list. However, trying to get the list of outputs
doesn't work:
observe( print(reactiveValuesToList(output)) )
How do I get the list of all rendered elements / all output elements?
A demo app to show how it works for input, but doesn't work for output elements
library(shiny)
rm(list = ls(), envir = globalenv()) ## to prevent cross over from old runs
ui <- dashboardPage(
dashboardHeader(title = "Dummy App"),
dashboardSidebar(
sidebarMenu(id = "tabs",
menuItem("HOME", tabName = "Home", icon = icon("home")),
menuItem("Page", tabName = "page1", icon = icon("pie-chart"))
) ),
dashboardBody(
tabItems(
tabItem(tabName = 'Home',
br(),
h1("WELCOME TO THE TEST APP", style = 'text-align: center;' )
),
tabItem(tabName = 'page1',
fluidRow(
uiOutput("BatchName")
)))))
server <- function(input, output, session) {
output$BatchName <- renderUI({ textInput(inputId ="BatchName", label = NULL , placeholder = "start") })
observe(print(reactiveValuesToList(input)) )
observe( print(reactiveValuesToList(output)) )
outputOptions(output, "BatchName", suspendWhenHidden = FALSE) ## without this line updating elements on page 2 and higher doesn't work as they are suspenWhenHidden = True by default
updateTextInput(session, inputId = "BatchName", value = "Updated")
}
shinyApp(ui, server)
Along with Shiny elements, you can use HTML elements to stylize your content in your application. In my opinion, R Shiny is very easy to learn despite how powerful the tool is. If you're working on a side project or looking to add something to your portfolio, I highly recommend trying it out.
Simply call shinyalert() with the desired arguments, such as a title and text, and a modal will show up. In order to be able to call shinyalert() in a Shiny app, you must first call useShinyalert() anywhere in the app's UI.
2.2. 1 Common structure. All input functions have the same first argument: inputId . This is the identifier used to connect the front end with the back end: if your UI has an input with ID "name" , the server function will access it with input$name .
Looking at the documentation for ?outputOptions
, if you don't pass in a name you'll get a list for all the possible output options. Then you can iterate that list to get set all the properties you want.
outs <- outputOptions(output)
lapply(names(outs), function(name) {
outputOptions(output, name, suspendWhenHidden = FALSE)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With