below is the sample UI. I wanted to check if there is way to list the values of input values. For example
ui.R
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("n", factors(iris$Species)),
actionButton("add", "Add")
),
# Show a plot of the generated distribution
mainPanel(
verbatimTextOutput("sum", placeholder = TRUE)
)
)))
Expected Output
Since we have iris$Species as one of the inputs. Is there a way to list them in R console?
I am not able to understand. print will actually print it in console. If you mean, you want to capture in a variable use <<- operator to export it in globalEnv
Outside of server, you will have to use print(isolate(input$n)). But this will capture only the first output and will no longer remain reactive.
Will check. Actually friend my question was little tricky. Let me put it this way. Say I have an application like above. I have not run the application. But still I want to know what goes into input$a. This is actually I meant by outside server side:blush:
I never thought to try this before, but it seems to work, listing all the things that can be referenced by input$mywhatever.
#somewhere in your reactive server code
list_of_inputs <- reactiveValuesToList(input)
print(list_of_inputs) # send to console
# or to have access to it globally when have run your program and exited it
list_of_inputs <<- reactiveValuesToList(input)
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
textInput(inputId = "mytextinput",label="mytextinput",value="text"),
numericInput(inputId="mynumericinput",label="mynumericinput",value = 5)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
print("started shiny")
observeEvent(input$bins,{
list_of_inputs <<- reactiveValuesToList(input)
print(list_of_inputs)
cat("input$bins: ", input$bins,"\n")
})
}
# Run the application
shinyApp(ui = ui, server = server)
Thanks a lot Nir. I did try this approach. But actually before running the application it self I should be able to get those. Like what Aurele did😊 thanks for this Aurele. But really not sure why it is not working in my system
Ok, so I feel like I should just make a gentle warning, that it would only be possible for a given complexity of app to do exactly what you desire. I believe this is because apps can be dynamic, they can have modules, inputs can exist and disappear, you can work with some apps, where you have 20 inputs and then 10 minutes later 7 inputs or 70 or whatever... So just to caution that approaches of scanning the top level UI is only practical for simpler cases of static apps.
This is even truer for any app that wants to read in available selection choices for some input$s from columns from tables that haven't even been loaded yet...
I wanted to check with you all that is there a way to check all inputs and outputs declared in Shiny app. For example for the below ui.R there are 2 inputs and 1 outputs
ui.r
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
numericInput("n", "Number to add", 5),
actionButton("add", "Add")
),
# Show a plot of the generated distribution
mainPanel(
verbatimTextOutput("sum", placeholder = TRUE)
)
)))