I am trying to create a web-form from shiny app that will take certain user inputs and save it in a dataframe and append that for each user in the dataframe. Finally this could be exported in csv or excel format.
I am new in R / RShiny and have basic understanding of R, dplyr, and now learning Shiny and facing challenges.
So far I have tried this code:
UI
library(shiny)
library(shinydashboard)
# Define UI for application
ui <- fluidPage(
headerPanel(title = "Reactive text widget"),
sidebarLayout(
sidebarPanel(
textInput("fullname","Enter your complete name"),
selectInput("city", "Choose your City",
choices = c("London","Chester","Manchester")),
textInput("phone", "Enter your Mobile Number"),
radioButtons("status", "Choose your martial status",
choices = c("Single","Married","Divorced"), inline = T),
selectInput("activity", "Choose your fitness activity",
choices = c("Gym","Yoga","Dance","Sports"),multiple =T),
sliderInput("age", "Enter your age (in years)",
min = 1, max = 150, value = 35, step = 1), br(),
sliderInput("weight", "Enter your weight (in Kgs)",
min = 1, max = 180, value = 70, step = 1),
sliderInput("targetweight", "Enter your desired weight range (in Kgs)",
min = 40, max = 150, step = 1, value = c(50,65)),
submitButton("Submit Form")
),
mainPanel(
textOutput("full_name"),
textOutput("current_city"),
textOutput("mobile_no"),
textOutput("martial_status"),
textOutput("fitness_Activity"),
textOutput("person_age"),
textOutput("weight_kgs"),
textOutput("desired_weight"),
tableOutput("my_table")
)
)
)
Server
# Define server logic
server <- function(input, output, session) {
output$full_name <- {(
renderText(input$fullname)
)}
output$current_city <- {(
renderText(input$city)
)}
output$mobile_no <- {(
renderText(input$phone)
)}
output$martial_status <- {(
renderText(input$status)
)}
output$fitness_Activity <- {(
renderText(input$activity)
)}
output$person_age <- {(
renderText(input$age)
)}
output$weight_kgs <- {(
renderText(input$weight)
)}
output$desired_weight <- {(
renderText(input$targetweight)
)}
# Creating Data Frame from User inputs ------------------------------------
observe({
Name <- input$fullname
City <- input$city
Phone <- input$phone
Martial_Status <- input$status
Fitness_Activity <- input$activity
Age <- as.integer(input$age)
Weight <- as.numeric(input$weight)
Desired_Weight <- input$targetweight
df_user <- as.data.frame(cbind(Name, City, Phone, Martial_Status, Fitness_Activity,
Age, Weight, Desired_Weight))
})
observeEvent({
output$my_table <- renderPrint(df_user())
})
}
# Run the application
shinyApp(ui = ui, server = server)
Will also appreciate if someone can share good resources to learn Rshiny from.
Thanks !!