conditionalPanel condition contained in a list - r

So, I have a checkboxgroupButtons where the user can select one or more options
checkboxGroupButtons("id","select options",
choices = c( "A","B","C" )
,selected = "A"
, checkIcon = list(yes = icon("ok", lib = "glyphicon"))
, direction = "vertical"
)
Then I want a conditional panel, but I want it such that the action depends if user selects "A" or (inclusive) "B". Already tried &&. Tried || but it doesn't logically accepts the inclusion. also tried
input.id.values, but it triggers even if I select "A" and "C".
conditionalPanel( condition = "input.id=='A' || input.id=='B'" , helpText("something") )
How can I set a condition is : "input.id" contained in the list ("A","B")
Thank you

Not sure, but could you try
input.id.every(i => i === 'A' || i === 'B')
Or, if the browser you use does not support =>:
input.id.every(function(i){return i==='A' || i==='B';})

Related

How do I display a text output when I click deselect all?

For my shiny app, I am using a pickerInput. When "deselect all" is selected, the output of my datatable shows an error. I am looking to print a string that says " Make sure to select an option!" when deselect all is selected. Do I have to use observeEvent, or can I use an if statement in my server code?
Here is an example of the pickerInput code:
pickerInput("type", "Select Option", choices = c("a","b","c", "d"), selected = c("a","b","c","d"), options = list('actions-box' = TRUE), multiple = T)
Here is an example of the server code:
output$one<- DT::renderDT({DT::datatable(caption = "table", options = list(pageLength = 50),tab1<- rbind(red, blue,green, yellow)%>% filter(num> .450, letter == input$type))
If error you can hide the datatable or return NULL and display a message via shinyalert.

How can I adapt this Power query recursion to handle multiple Parents in a hierarchy?

I'm trying to adapt the recursion code below, to handle the situation where there can be multiple ParentId for each Id (This is where I found the code on SO).
I see that the List.PositionOf can take an optional parameter with Occurence. All so that instead of returning the position of the Id in the List, I can return a list of the positions of all the matching Ids.
The problem I have is what to do next.
How can I use this list of positions to get the list of ParentId elements in the ParentID_List corresponding to these positions? Or is there a better approach?
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
ChangedType = Table.TransformColumnTypes(Source,{{"ID", type text}, {"ParentID", type text}}),
ID_List = List.Buffer( ChangedType[ID] ),
ParentID_List = List.Buffer( ChangedType[ParentID] ),
Type_List = List.Buffer( ChangedType[Type] ),
Highest = (n as text, searchfor as text) as text =>
let
Spot = List.PositionOf( ID_List, n ),
ThisType = Type_List{Spot},
Parent_ID = ParentID_List{Spot}
in if Parent_ID = null or ThisType=searchfor then ID_List{Spot} else #Highest(Parent_ID,searchfor),
FinalTable = Table.AddColumn( ChangedType, "StrategyID", each Highest( [ID],"Strategy" ), type text),
FinalTable2 = Table.AddColumn( FinalTable, "SubstrategyID", each Highest( [ID],"Substrategy" ), type text),
#"Replaced Errors" = Table.ReplaceErrorValues(FinalTable2, {{"SubstrategyID", null}})
in #"Replaced Errors"

Earliest Time in Datetime column PowerBI

Okay so I have a table like shown...
I want to use PowerBI to create a new column called 'First_Interaction' where it will say 'True' if this was the user's earliest entry for that day. Any entry that came in after the first entry will be set to "False".
This is what I want the column to be like...
Use the following DAX formula to create a column:
First_Interaction =
VAR __userName = 'Table'[UserName]
VAR __minDate = CALCULATE( MIN( 'Table'[Datetime] ), FILTER( 'Table', 'Table'[UserName] = __userName ) )
Return IF( 'Table'[Datetime] = __minDate, "TRUE", "FALSE" )
Power BI dosnt support less than second so your DateTime Column must be a Text value. Take that on consideration for future transformation.

DAX: How to check if (All) value selected for specific Dimension

I have a task to convert existing MDX measures (from multidimensional model) into DAX (tabular model).
There is a part of code which I'm doing right now:
IIF(
[Product].[Status].Level IS [Product].[Status].[(All)]
AND
[Product].[Brand].Level IS [Product].[Brand].[(All)]
AND
[Product].[Category].Level IS [Product].[Category].[(All)]
,[Measures].[Full_Amount]
,NULL
)
How can I do the same on DAX?
The problem is to check that .[(All)] member is selected. Do we have the same option n DAX?
As #RADO mentions you can do something like this in DAX:
IF(
NOT ISFILTERED( Product[Status] )
&& NOT ISFILTERED( Product[Brand] )
&& NOT ISFILTERED( Product[Category] ),
[Measures].[Full_Amount],
BLANK()
)

Shiny conditionalPanel conditions based on NULL values in R?

I am writing a Shiny application that will query a database a few times. The queries may take some time, so I am using actionButton to allow the user to control when they are started.
The general flow of the application is:
User loads page, pushes button to load in available choices from the database.
User selects a row from the available choices, and then kicks off a larger query that will take longer.
When the query is done, the user will get nice visualizations and other such things.
I know that you can allow the user to select rows from a DataTable using the selection option, and I am currently using the development build so that single-selection can be enabled. My problem is figuring out how to hide certain conditional panels until the user has made a choice. As far as I can tell, the value of the choice is stored in input$[data frame name]_rows_selected. But, until the values are selected, this value is either NULL, or does not exist.
I cannot figure out how to pass to the condition argument of conditionalPanel() a condition which reflects the internal R logic. I've written a minimal working example below which shows the behavior to which I'm referring.
library(shiny)
library(DT)
# Create sample data
df_sample_data <- data.frame(name = c("John Smith","Jane Cochran","Belle Ralston","Quincy Darcelio"),
color = c("Red","Blue","Red","Green"),
age = c(25,52,31,29))
ui <-
fluidPage(
titlePanel("The Title!"),
sidebarPanel(
h1("Load Data"),
actionButton("load_data","Load Data"),
br(),
conditionalPanel(
h1("Do Thing"),
actionButton("do_thing","Do Thing"),
condition = "input.df_data_rows_selected !== undefined")
),
mainPanel(
dataTableOutput("df_data"),
conditionalPanel(
tableOutput("row_selected"),
condition = "input.df_data_rows_selected !== undefined")
)
)
server <-
function(input, output) {
# This function loads the data (in reality it is a server operation)
uFunc_ReactiveDataLoad <- eventReactive(eventExpr = input$load_data,valueExpr = {
df_data <- df_sample_data
return(list(display_table = datatable(data = df_data[c("name","age")],
options = list(dom = "tip"),
filter = "top",
selection = "single",
colnames = c("Person Name" = "name",
"Person Age" = "age")),
data_table = df_data))
})
output$df_data <- renderDataTable(expr = uFunc_ReactiveDataLoad()$display_table)
output$row_selected <- renderTable(expr = uFunc_ReactiveDataLoad()$data_table[input$df_data_rows_selected,])
}
shinyApp(ui = ui, server = server)
In the current setup, which uses input.df_data_rows_selected !== undefined, the panels are hidden until the data is loaded using the first actionButton. But, I need them to remain hidden unless the user has selected a row. I have tried other things such as:
input.df_data_rows_selected !== null
input.df_data_rows_selected !== 'null'
input.df_data_rows_selected !== ''
input.df_data_rows_selected !== 'NULL'
...and so on, but I have had no luck. How does the NULL value in R get represented in the JavaScript used for the condition argument to conditionalPanel()?
condition = "(typeof input.df_data_rows_selected !== 'undefined' && input.df_data_rows_selected.length > 0)" for both entries seems to work.
condition = "(typeof input.df_data_rows_selected === null")
If anyone is stumbling upon this issue a few years later...

Resources