I have an app that I where I want to ask a question up front in say a pop up dialogue box, have the question answered, have the box disappear, and then have my app run.
I have searched for over a week and have tried many things to no avail. I have tried just readline()
. I have looked at ShinyBS but none of the examples are functioning. I have looked into tcltk2. While I didn't get any errors, nothing happened to include no dialogue box.
Here is a simple example of what I would like to do.
Suppose I just want a pop up box to ask, What is your name?
After the name is inputed, the box closes, and the app begins. Perhaps the app now says, Hello Name.
Please help me update the code below.
library(shiny)
library(tcltk2)
library(shinybs)
#Create pop up box asking name. Then substitute this value into XXX below.
ui <- shinyUI(fluidPage(
# Application title
titlePanel("Hello XXX, how are you?")
)
)
server <- shinyServer(function(input, output) {
})
# Run the application
shinyApp(ui = ui, server = server)
For completeness, here is the code I wrote. This was gleaned from the link Pork Chop referenced. It works, although some parts I still don't understand.
library(shiny)
Logged = FALSE;
ui1 <- function(){
tagList(
div(id = "login",
wellPanel(textInput("name", "Name"),
br(),actionButton("submit", "Submit"))),
tags$style(type="text/css", "#login {font-size:10px; text-align: left;position:absolute;top: 40%;left: 50%;margin-top: -100px;margin-left: -150px;}")
)}
ui2 <- function(){fluidPage(
# Application title
titlePanel({
fluidRow(column(12,
textOutput("greeting")))
})
)}
ui = (htmlOutput("page"))
server = (function(input, output,session) {
USER <- reactiveValues(Logged = Logged)
observe({
if (USER$Logged == FALSE) {
if (!is.null(input$submit)) {
if (input$submit > 0) {
Username <- isolate(input$name)
if (length(Username) > 0 ) {
USER$Logged <- TRUE
}
}
}
}
})
observe({
if (USER$Logged == FALSE) {
output$page <- renderUI({
div(class="outer",do.call(bootstrapPage,c("",ui1())))
})
}
if (USER$Logged == TRUE)
{
output$page <- renderUI({
div(class="outer",do.call(fluidPage,ui2()))
})
print(ui)
}
})
output$greeting <- renderText({
print(paste("Hello, how are you", " ", input$name,"?", sep = ""))
})
})
runApp(list(ui = ui, server = server))