conditionalPanel javascript conditions in shiny: is there R %in% operator in javascript?
According to this answer this condition should work (and it works for me)
condition = "input.ModelVariables.indexOf('TP53') > -1"
javascript condition contains for conditionalpanel in shiny
Try
condition = "input.products.indexOf('C') > -1"
condition as a vector in conditionalPanel using shiny
I turned multiple
to FASLE
because I'm not sure what's the desired condition in your mind if there is overlap.
How it works is that you need to insert your javascript array in your UI first.
Also, your javascript syntax in the condition is wrong, the correct one should be:array1.indexOf(input.control) > -1
The following example works.
# ----
library(shiny)
library(shinydashboard)
# header ----
header <- dashboardHeader(title = "Example")
#sidebar ----
sidebar <- dashboardSidebar(disable = T)
#body ----
body <- dashboardBody(
# insert javascript code in UI -----------------------
tags$head(
tags$script("var array1 = ['a','c', 'f'];")
),
fluidRow(
column(
width = 12,
selectInput(
inputId = "control",
label = "choose something:",
choices = c("a",
"b",
"c",
"d",
"e",
"f"),
multiple = FALSE
)
)
),
conditionalPanel(
condition = "array1.indexOf(input.control) > -1", # change code here
textInput(inputId = "first", label = "first test")
)
)
# all ui ----
ui <- dashboardPage(
header = header,
sidebar = sidebar,
body = body
)
# server ----
server = shinyServer(function(input, output) {
})
# Run the application
shinyApp(ui = ui, server = server)
Evaluating beyond input conditions in R Shiny conditionalPanel
There is no reason to write reactives to conditionally show/hide elements. Take a look at shinyjs
instead by Dean Attali
Example of using shinyjs
:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
actionButton("show", "Click me once to show stuff!"),
actionButton("toggle", "Click me any times to toggle stuff!"),
hidden(
div(id = "d1",
"Content hidden until button is clicked"
)
),
hidden(
div(id = "d2",
"Content toggled when button is clicked"
)
)
)
server <- function(input, output) {
observeEvent(input$show, {
show("d1")
})
observeEvent(input$toggle, {
toggle("d2")
})
}
shinyApp(ui, server)
R Shiny: conditionalPanel not working if used several widgets
Problem with compare numeric
and character
in js
You need to use 0 only for numerict results ( actionButton and selectInput in your example)
You need such condition input.id1>'' && input.id2>'' && input.line>0&& input.dateRange>'' && input.update>0
Shiny conditionalpanel not evaluating at startup
As @porkchop pointed out, you can create the condition in the renderUI function of server.R
:
Server.R:
shinyServer(function(input, output,session){
output$selectInput1 <- renderUI({
selectInput(
inputId = "select1",
label = "Select",
choices = c('1','2','3'),
selected = NULL,
multiple = TRUE
)
})
output$panel1 <- renderUI({
if(!is.null(input$select1) && length(input$select1) > 0){
condition1 = 'true'
} else {
condition1 = 'false'
}
conditionalPanel(
condition1,
p('hi')
)
})
})
UI.R:
dashboardPage(
title = "",
## Header content + dropdownMenu
dashboardHeader(
title = tags$b(""),
titleWidth = 250
),
## Sidebar content
dashboardSidebar(
width = 250,
sidebarMenu(
id = "tabs",
menuItem("tab1", tabName = "tab", icon = icon("table"))
)
),
## Body content
dashboardBody(
tabItems(
tabItem(tabName = "tab",
div(
div(
style="float: left; padding-left: 20px; padding-right: 20px; width: 350px; background-color: #F4F4F4; height: calc(100vh - 50px) !important;",
uiOutput('selectInput1')
),
div(
uiOutput('panel1')
)
)
)
)
)
)
Related Topics
Shiny: Start the App with Hidden Tabs, with No Delay
How to Detect Emoji Using JavaScript
How to Geocode 20 Addresses Without Receiving an Over_Query_Limit Response
How to Serialize Dom Node to JSON Even If There Are Circular References
Uint8Array to String in JavaScript
Stop a Youtube Video with Jquery
Passing a Function with Parameters as a Parameter
Deprecation Warning in Moment.Js - Not in a Recognized Iso Format
Clear Text Selection with JavaScript
Why Does the Promise Constructor Need an Executor
Programming Language Independent Model Validation
How to Use Jquery in Firefox Extension
Explanation of [].Slice.Call in JavaScript
The Definitive Best Way to Preload Images Using JavaScript/Jquery