Reg : Shiny ::Displaying required field validator message to users

617 views
Skip to first unread message

Manohar Reddy

unread,
May 22, 2017, 8:09:47 AM5/22/17
to Shiny - Web Framework for R, Manohar Reddy

Hi ,

 

  I would like to display some required field validator message (Like please enter search keyword) to users whenever they didn’t passed any inputs to textbox and clicked on searched button.

 Here is my sample reproducible code ,please check and advise me .Thanks in Advance ..



​code : 

library(shiny)
library(DT)

ui <- fluidPage(
  
  headerPanel("test"),
  sidebarLayout(
    sidebarPanel(
      fluidRow(column(6,textInput("NSearch", label = h3("Contacts Search :"))),column (3,actionButton(inputId = "SAction", label = "Search",color= "blue")))
    )
    ,mainPanel(dataTableOutput("d1"))
  )
)

server <- function (input,output){
  
  
  observeEvent(input$SAction, {

    validate(
      need(input$NSearch != "" ,  message ="must be provided")
      
    )
    
    a = input$NSearch
    b = subset(iris,iris$Sepal.Length > a)
    output$d1 = renderDataTable(b)
    
  })
  
}

shinyApp(ui,server)

Manu.

Winston Chang

unread,
May 22, 2017, 4:48:10 PM5/22/17
to Manohar Reddy, Shiny - Web Framework for R
If I understand correctly, you can use textInput's placeholder argument for this.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/CADG9u0BtmuAkrEbeL4Np9ke2tmbR9p%2BdNUeW0hrFReEwQ9K9iQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Manohar Reddy

unread,
May 22, 2017, 8:50:56 PM5/22/17
to Winston Chang, Shiny - Web Framework for R
Thanks Chang, can you please share me the sample code on same .


Manu.

Joe Cheng

unread,
May 22, 2017, 9:09:04 PM5/22/17
to Manohar Reddy, Winston Chang, Shiny - Web Framework for R
This is incorrect:

  observeEvent(input$SAction, {

    validate(
      need(input$NSearch != "" ,  message ="must be provided")
      
    )
    
    a = input$NSearch
    b = subset(iris,iris$Sepal.Length > a)
    output$d1 = renderDataTable(b)
    
  })

This is correct:

b = eventReactive(input$SAction, {
    validate(
      need(input$NSearch != "" ,  message ="must be provided")
    )
    
    a = input$NSearch
    subset(iris,iris$Sepal.Length > a)
})
output$d1 = renderDataTable(b())

To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/CADG9u0CFvcjDkN%3DsNDHQ--5hPy4ZxmT6uBWtgd_2JXFzNtaDYQ%40mail.gmail.com.

Manohar Reddy

unread,
May 23, 2017, 12:57:27 AM5/23/17
to Joe Cheng, Winston Chang, Shiny - Web Framework for R

 Thanks Joe,


  In one case it’s working fine (whenever there is one output under search button ),but in my second case is advanced search based on this result I’m displaying data with DT and plotting graphs as well generating dynamic UI based on my input parameters ,now if I take out those events from event reactive I couldn’t able to meet my requirement ,probably below screen shot give more clarity on what I’m trying to achieve.

 

 Inline image 1

 

 

   Here I will explain how my application supposed to work

 

  1. There is a normal search, user need to enter some keyword and need to click on search button ,if user didn’t passed any input and if they clicked it on search button I’m showing required filed validator message  like (please enter search keyword ).   ---à I have achieved now .

 

  1. There is a advance search ,user need to pass search keyword and need to select some inputs like start date ,end date ,search scope ,result view if not selected by default default values were selected ,here also I need to put same condition when user didn’t passed any inputs to search bar needs to throw same error message here I can’t able to achieve this as I need put all my tables data and graphs data under search button only .

 

  1. If       you observer above screen shot I’m getting 2 empty lines ,don’t know why I’m getting (here I’m displaying normal search and advanced search results ),can you please suggest me how can i remove those empty lines.

 

             Please let me know if you need some information on same to address these issues ,thanks in Advance .


Manu.


To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.



--


Manu.

Joe Cheng

unread,
May 23, 2017, 1:44:59 PM5/23/17
to Manohar Reddy, Winston Chang, Shiny - Web Framework for R
I don't understand this part:

>  I can’t able to achieve this as I need put all my tables data and graphs data under search button only .

Can you elaborate? Are you saying the challenging part here is that there are two search buttons, and you need to be able to respond to both, and to know which one was clicked (or, clicked most recently)?

To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.



--


Manu.

Manohar Reddy

unread,
May 23, 2017, 11:11:05 PM5/23/17
to Joe Cheng, Winston Chang, Shiny - Web Framework for R

Thanks Joe,

 

Here I  will explain the part which  you are unable to understand .

 

 In that UI page I’m giving 2 search options to users 1.Normal search 2. Advanced Search

 

1.Normal search :

 

    Whenever user don’t want to pass all the values just they will pass search keyword and will hit the search button ,based on input I’m showing data on same page (done).

 

2.Advanced search :

 

  In this search user needs to pass all the input values like in my case search keyword ,start date,end date ,etc..based on these input parameters in backend I’m preparing sql query and displaying data as well plotting few graphs based on result set.

 

   Whenever user pass the inputs for advanced search and hit the search button in same page I’m showing result set along multiple graphs ,so I need to put DT (for displaying data) and plotly (for plotting multiple graphs) under advanced search button only.

 

  Please let me know still if you need more information on same,.

                      Or

   Please let me know is there any way that I can achive my requirement . 

      

Help would be greatly appreciated .


Manu.


To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discuss+unsubscribe@googlegroups.com.



--


Manu.



--


Manu.
Reply all
Reply to author
Forward
0 new messages