I have a problem in regards to the post: Collect all input labels in Shiny R.
I have created a simple app based on the code from above mentioned post. So far I am able to select all the variables in a dataset and automatically create an UI consisting of input widgets based on the variables in the dataset. I am also able to display all the selected inputs in a table below. The whole idea is to create an application that will work the same when a different dataset is uploaded. (see code below).
The problem arise when I add a new object which gets stored as a input value. For example if I create an action-button. If I do this, the ID of the action-button will get displayed in the display-table and I don't want this.
If you don't understand what I mean, try to run the code below and notice in the display-table that one of the objects displayed is the "savebutton", which is the ID of the action-button on the page. I only want to display the input values from the variables in a given dataset that is uploaded to the app (in this case, it would be the variables in the dataset iris, but it should work on other datasets as well).
How can I modify my code to only show the input values from the variables in the dataset?
library(shiny)
library(tidyverse)
library(readxl)
library(shinythemes)
library(data.table)
library(RCurl)
library(randomForest)
# Read data
DATA <- datasets::iris
ui <- fluidPage(
h3("Input-widgets:"),
uiOutput("select"),
hr(),
h3("display-table:"),
br(),
tableOutput('show_inputs'),
hr(),
h3("Save button"),
actionButton("savebutton", label = "Save", icon("save")),
br(),
"The button has no function right now other than to show the problem in the display-table"
) # End UI bracket
server <- function(input, output, session) {
# Create input widgets from dataset
output$select <- renderUI({
df <- req(DATA)
tagList(map(
names(df[-1]),
~ ifelse(is.numeric(df[[.]]),
yes = tagList(sliderInput(
inputId = paste0(.),
label = .,
value = mean(df[[.]], na.rm = TRUE),
min = round(min(df[[.]], na.rm = TRUE),2),
max = round(max(df[[.]], na.rm = TRUE),2)
)),
no = tagList(selectInput(
inputId = paste0(.),
label = .,
choices = sort(unique(df[[.]])),
selected = sort(unique(df[[.]]))[1],
))
)
))
})
# Display the input selections
AllInputs <- reactive({
myvalues <- NULL
for(i in 1:length(names(input))){
myvalues <- as.data.frame(rbind(myvalues,(cbind(names(input)[i],input[[names(input)[i]]]))))
}
names(myvalues) <- c("Variable","Selected Value")
myvalues
})
output$show_inputs <- renderTable({
AllInputs()
})
} # End server bracket
shinyApp(ui, server)