are you hosting this yourself so you can scoop up the csv files at your convenience, or would you publish on shinyapps ? because it would seem to be a problem for you how to get the data out.
Perhaps you would do best with a database back end for permanest storage purposes
Yes. I would be hosting on ShinyApps. and would be going with mySql data base for the storage purposes.
But intitally I am not able to store my data in a dataframe so that I can save it later wither in csv or database.
library(shiny)
library(tidyverse)
ui <- fluidPage(
textInput("my_in","type a value for an entry"),
actionButton("newline_but","press for a new entry"),
tableOutput("showmytable")
)
server <- function(input, output, session) {
mydf <- reactiveVal(tibble(msg=NA_character_))
output$showmytable <- renderTable({
mydf()
})
observeEvent(input$my_in,{
local_df <- req(mydf())
curr_row <- nrow(local_df)
local_df[curr_row,1] <- input$my_in
mydf(local_df)
})
observeEvent(input$newline_but,{
local_df <- req(mydf())
mydf(add_row(local_df))
})
observeEvent(mydf(),
{
#export to a global but would be better to maybe write to a database
assign(x="exported_df",
value=mydf(),
envir = .GlobalEnv)
})
}
shinyApp(ui, server)
Yours is working fine.
But my code is this guide me here.
ui<- fluidPage(useShinyjs(),
tags$head(tags$link(rel="stylesheet", href="style.css")),
titlePanel("Registration"),
fluidRow(column( width = 8,
div(
textInput("message", label = "",placeholder = "Type your message here."),
actionButton("send", "Send")
)
)))
# Defining Server Controls
server<- function(input, output, session)
{
# Declaring and Initializing Global Variables
i <- 1
lvl <- reactiveVal()
lvl(i)
exam <- matrix(c("Yes", "No"), byrow =F, nrow = 1)
score <- reactiveValues(marks = 1 )
#Clear Function
clearInput<- function()
{
updateTextInput(session,"message", value = "")
}
#Invalid Function
invalidInput<- function()
{
insertUI(
selector = "#message",
where = "beforeBegin",
ui=div(class="chat-bubbles",
div(class="bubble",p("Kindly provide a valid input."))
), immediate = TRUE
)
clearInput()
}
replyMessage<- function(lvl,msg)
{
message('Level:', lvl)
message('Message:', msg)
switch(lvl,
# Check for Level 1
if(grepl("^[a-zA-Z][a-zA-Z ]+[a-zA-Z]$",msg, perl=T)){
insertUI(selector = "#message", where = "beforeBegin",
ui= div(class="chat-bubbles",
wellPanel(
p("Hi",tags$b(input$message),tags$br(),"What country are you looking to study in?"),
tags$br(),
div(class="bubble admin",
wellPanel(
p("Please enter your 10 digit mobile number.")
)
), immediate = TRUE)))
shinyjs::enable("message")
shinyjs::show("send")
clearInput()
lvl(lvl +1)
}
else
{
invalidInput()
runjs('
document.getElementById("bottom").scrollIntoView();
')
},
# Check for Level 2
if(grepl("^[1-9][0-9]*$", input$message) & nchar(input$message)==10)
{
insertUI(selector = "#message", where = "beforeBegin",
ui=div(class="chat-bubbles",
div(class="bubble user",style="text-align: right;",
p(tags$b(input$message), tags$br())),
div(class="bubble admin",
wellPanel(
p("Have you taken your Graduation test"), tags$br(),
actionBttn("c1", "Yes",color = "primary", style = "material-flat",block =TRUE, size = "xs" ), tags$br(),
actionBttn("c2", "No",color = "warning", style = "material-flat",block =TRUE, size = "xs")
)
)), immediate = TRUE)
clearInput()
shinyjs::disable("message")
shinyjs::hide("send")
lvl(lvl + 1)
runjs('
document.getElementById("bottom").scrollIntoView();
')
}
else
{
if (lvl != 3) {
lvl(3)
}
invalidInput()
runjs('
document.getElementById("bottom").scrollIntoView();
')
}
)
}
# Function to check blank in Message box
getMessage<- function(lvl)
{
# Observer Event for Message Box
observeEvent(input$send,{
if(input$message == '')
{
insertUI(
selector = "#message",
where = "beforeBegin",
ui=div(class="chat-bubbles",
div(class="bubble admin",
p("Kindly provide a valid input."))
)
)
clearInput()
}
else
{
replyMessage(lvl(),input$message)
}
})
#Observe Event for exam Taken
lapply(sprintf("c%s", 1:2),
function(x)
{
observeEvent(input[[x]],{
score$marks <- as.numeric(sub("c", "", x))
insertUI(selector = "#message", where = "beforeBegin",
p(paste(
replyMessage(lvl(),exam[, score$marks])))
)
})
shinyjs::disable("c1")
shinyjs::disable("c2")
})
}
# Main Function
startConversation<- function()
{
clearInput()
insertUI(
selector = "#message",
where = "beforeBegin",
ui=div(class="chat-bubbles",
div(class="bubble admin",
p( "Hey! Can I get your name please?")
)))
getMessage(lvl)
}
startConversation()
}
shinyApp(ui,server)
I think you should take the time to consider my code and think how to adapt the knowledge.
ok. let me go through this.
This guide by @merlinoa may be helpful.
It demonstrates a create, read, update, and delete (CRUD) #shiny app.
Hi Nir,
I tried your code. It's working fine. But the challenge is I have to save the form data for single user in one row only. And when the multiple users use the form, one user's data shall be saved in a single row only.
For multiple users you need a database
I have connected to the database. My form contains- Name, Phone number, Country etc.
and in the database, the rows are showing like this-
.
It's a single user data. There should be only I row for each user' data. But for single user only, it is taking each row for each event(name, phone number, country)
How to overcome this?
Update is the U in CRUD
Can you be more specific please?
I am using-
dbWriteTable(mydb, value = mydf(), name = 'table name', row.names=FALSE, append=T,
overwrite=F)
I don't think so. You aren't asking a precise R question. Rather it seems you are unsure about what it means to edit/update an object.
If you are simply appending to an existing table as per your code example, then you are very aware that you aren't editing an existing row. I don't currently use a database myself so I'm not the best person to guide you about it as my interest is low. Perhaps you should start a brand new thread where you ask a specific question about working with databases. I suggest you leave shiny out of it for the time being
Well, I am just trying to update my database with different input values from different users.
Will create a new thread Thanks!