I want to make it working when multiple values entered. please find attached file, with (fig 1)single value working. (Fig 2) two values and throws error.
A textual description of an error is not as useful as a coding example. To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this resources, to see how to create one for a shiny app
I am able to create Shiny App and produce the output. I have drop down and multiline text box in my UI
shinyUI(
pageWithSidebar(
headerPanel("The Team analysis"),
sidebarPanel(
selectInput("SFAM","Select Team",choices = c("A","B"),selected = FALSE),
h4("Multi-line text input test"),
tags$style(type="text/css", "textarea {width:100%}"),
tags$textarea(id = 'input_text',placeholder = 'Type here', rows = 8, ""),
verbatimTextOutput("output_text"),
actionButton("Run","click me")
),
I am connecting the text from multiline text box to subset a R dataframe.
when I am typing a single value its giving the result with graph in place.(a bar or line chart), R code is as follows;
Server:
```R
shinyServer(
function(input,output){
output$MyPlot<-renderPlot({
data2<-subset(data,data$team %in% input$input_text)
ggplot(data2, aes(x=data2$team)) +
geom_bar(aes(y=data2$Count), fill='deepskyblue4', stat="identity")
}
})
```R
When I am entering multiple value in multiline text box, am getting empty dataframe which result in no graph.
1. I want to know is there any other text box which can accommodate multiple entry and pass it to subset using "in"
**"data2<-subset(data,data$team %in% input$input_text)"**
2. How we can enter value in multi line text box whether comma separated or quotes separated,
example: Team1, Team2 or "Team1" "Team2".
Please help me with this..
%in% compares two vectors. You have a vector on the left, but on the right you have a single string with one or more team names. You need to split the right hand side into a vector. Maybe str_trim(str_split(input$input_text, ",")) would do it. These functions are from the stringr package
Also you don't need/shouldn't put data2$... in the aesthetic.
ggplot(data2, aes(x = team)) +
geom_bar(aes(y = Count), fill = 'deepskyblue4', stat = "identity")
Thanks for the reply, I tried it but the input is not taken to provide a valid Data frame. I am getting an empty dataset. I want to know any Shiny Text box or any other menu that can provide option for user to enter multiple value and with any specific format(so that, it can easily pass in R code).
I am giving the user input values as Team1,Team2. Is this ok that the value entered by user is separated by "Comma" and that "Input_text" in the filter but got error as "MISSING VALUES IN 'FILTER'"
If user selects Team1 its associated value should pop up in "Select Reference".
If user doesn't want to select values from "Select Reference", he can manually enter value in "Multi-line text Input test".
My issue is, how user can enter value in multiple text box, whether values needs to be separated by "comma"? or in which format. Once user entered value how it can be passed in R code.
Yeah, I tried it but getting the same. To be specific, I need to know how user inputs multiple values in a text box or any other input box that can be used to pass in a sql query or subset in R.
Example:
Multiple text box: Team2, Team4
SQL query:( select * from Team where teams in ("Multiple text box Values")
or
R Subset<-(subset(Team, Team$teams "%in%" ("Multiple text box Values")
Thank you [nirgrahamuk]: Yeah filter option sounds good. But in multiple text box if I enter single value its working, but multiple or even extra ,(comma) its not taking input.
Example: Team1 -- working
rather: Team1, -- Not working or Team1,Team2 also not working
Any other text box or option available in UI. Thanks in advance
I just found that its bringing all string with matching text in it.
after using the code:
filter(
mycars,
str_detect(string = carnames,
pattern = str_split(input$input_text, ",") %>%
unlist %>% str_trim() %>% paste0(collapse="|"))
```R
Example: if input is "Team1,Team2",
it is bringing all the values which has "Team1,Team2". i.e.. "Green/Team1, RedTeam2,TTeam2"
How can I get exactly matching string, i.e.. only "Team1" or "Team2" etc..
Any help on this.