R Shiny Set SelectizeInput default value as NULL
Try this one:
library(shiny)
fileNames = c('a', 'b', 'c', 'd', 'e')
ui <- fluidPage(
selectInput("request","Select Existing Request",
choice = c('Choose a File Name' = '', unique(fileNames)), multiple = FALSE,
selected = NULL)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
How to have default NULL value in Input & filter data only when non null value?
It worked when I made couple of changes .. not sure which one was the factor
- Instead of
null
used other text i.e "No State selected" & applied condition on it: - changed dataframe name
filtered_vaccine_center
tofiltered_vaccine
ui
selectInput(inputId = "vaccine_center_state_select",
label = "Select State to narrow your search",
choices = c("No State selected",unique(vacc_centers$state))
,selected = "No State selected"
,multiple = FALSE
),
server:
filtered_vaccine_centers <- reactive({
req(input$vaccine_center_state_select)
if(input$vaccine_center_state_select != "No State selected")
{
filtered_vaccine <- vacc_centers %>%
filter(state == input$vaccine_center_state_select)
}
else filtered_vaccine <- vacc_centers
}) %>%
bindCache(input$vaccine_center_state_select)
points of Vaccination Centers on lat, long axis without using country map coordinates
Output
Insert warning message from selectInput option
If you are open to using another package here is a shinyWidgets solution with a 'sendSweetAlert':
library(shinyWidgets)
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
radioButtons(
"filter1",
h3("Select properties"),
choiceValues = c(1, 2),
choiceNames = list(
tagList(
tags$span("All properties"),
tags$span(icon("info-circle"), id = "icon1", style = "color: blue;")
),
tagList(
tags$span("Exclude properties"),
tags$span(icon("info-circle"), id = "icon2", style = "color: blue;")
)
),
selected = 1
),
selectInput("filter2", h3("Select farms"),
choices = list("All farms" = 1,
"Exclude farms" = 2),
selected = 1),
),
mainPanel(
)
)
)
server <- function(input, output, session) {
observe({
if(input$filter2 == 2){
sendSweetAlert(
session = session,
title = "Warning!",
text = "Change filter options selected above",
type = "warning"
)
}
})
}
shinyApp(ui = ui, server = server)
All is needed is to observe the selectInput value and when the input is on "Exclude farms" which has a value of 2 a warning message is sent.
Datatable displays empy selectInput while values are selected by default
The words
list is named:
> name <- c("Jack","Bob","Jack","Bob")
> item <- c("apple","olive","banana","tomato")
> d <- data.frame(name, item)
>
> ( words <- tapply(d$item, d$name, I) )
$Bob
[1] olive tomato
Levels: apple banana olive tomato
$Jack
[1] apple banana
Levels: apple banana olive tomato
Therefore its JSON representation is:
> toJSON(words)
{"Bob":["olive","tomato"],"Jack":["apple","banana"]}
This is not an array. Remove the names and you get the wanted array of arrays:
> toJSON(unname(words))
[["olive","tomato"],["apple","banana"]]
Or instead of using 'jsonlite', use a basic JSON stringifier:
sprintf("[%s]", toString(vapply(words, function(x){
sprintf("[%s]", toString(shQuote(x)))
}, character(1))))
# "[['olive', 'tomato'], ['apple', 'banana']]"
Related Topics
How to Install Multiple Packages
How to Remove "Rows" with a Na Value
Clustering List for Hclust Function
More Efficient Means of Creating a Corpus and Dtm with 4M Rows
Select Unique Values with 'Select' Function in 'Dplyr' Library
Change the Index Number of a Dataframe
How to Convert Ensembl Id to Gene Symbol in R
How Does the Removesparseterms in R Work
Hiding Personal Functions in R
How to Create Textarea as Input in a Shiny Webapp in R
Comparison Between Dplyr::Do/Purrr::Map, What Advantages
Assign Headers Based on Existing Row in Dataframe in R
Keep Before and After Date of an External List