i am trying to build a simple shiny application with the following layout, 2X2 layout
Data1 Data2
Stats1 stats2
tabBox(title = "Data Review",id= "ttabs", width = 20, height = "420px",
tabPanel("Data",
column(3, dataTableOutput("data1"))
, column(3, verbatimTextOutput("sum1")),
, column(3, offset = 1,dataTableOutput("data2"))
, column(3, offset = 1, verbatimTextOutput("sum2"))
)
data 2 and stats2 appear as expected (one below the other), however data1 and stat1 appear side by side. Not sure how to update the code to get the expected result
How about use fluidRow()?
ui <- fluidPage(
tabBox(title="Data Review", id="ttabs", width=20, height=420,
tabPanel("Data",
fluidRow(
column(6, dataTableOutput("data1")),
column(6, dataTableOutput("data2")) ),
fluidRow(
column(6, verbatimTextOutput("sum1")),
column(6, verbatimTextOutput("sum2")) )
)
)
)
I hope this code help you.
Related
I'm having problems with implementing TOP N slicer into my dashboard. I would like to have a single select TOP 5, TOP 10, TOP 20 and TOP 30 slicer which will show items with the biggest count.
I partially managed to achieve this and it works while I have only one column added to the y-axis (I use horizontal bar chart) and my measure to the x-axis but when I add another column to legend field everything falls apart.
These are my measures:
TopN_test =
VAR Selected_Top = SELECTEDVALUE('Top N'[Select Top N])
RETURN
SWITCH(TRUE(),
Selected_Top = 0,[count_all_current],
RANKX(
ALLSELECTED(Skills[Skill correct]),
[count_all_current]
)
<= Selected_Top,
[count_all_current]
)
count_all_current =
CALCULATE(
COUNT('Skills'[Skill correct]),
FILTER('Skills', 'Skills'[DateIndex] = 6),
FILTER('Skills', 'Skills'[Proficiency]<>"-")
)
I will be grateful for any advice how to adjust it.
I added a calculate and Selected_Top Variable as a filter. Can you please check if this code works for you.
TopN_test =
SWITCH (
TRUE (),
Selected_Top = 0, [count_all_current],
RANKX ( ALLSELECTED ( Skills[Skill correct] ), [count_all_current] ) <= Selected_Top, CALCULATE ( [count_all_current], Selected_Top )
)
I have a simple problem. My DAX measure does not seem to be working correctly when I filter for non-existing values. Here are some details:
Table:
Column1: A,A,A,A,A,B,B,B,B
Column2: 1,2,3,4,5,1,2,3,5
Measure = calculate(countrows(table), allexcept(column1))
Card Visual returns correct row count when I filter by column1 (any value in filtering pane)
However it returns wrong row count when I filter by column2 = "4" and Column1 = "B" (in filtering pane). It seems that it should ingore filtering by column2 and it does except when I specifically filer for value = "4". It gives "blank" result value in a card visual then.
Any ideas why?
Here's the screen. I would like to populate that blank cell with "4" (in a singe-table data model.enter image description here
In your case you dont need to add allexcept in your measure. Below code would be fine.
TestMeasure = countrows(Test_Data)
PFB screenshot
I am hoping that you have a data model as following
table name _dim1
colA
A
B
C
table name _dim2
colB
1
2
3
4
5
table name _fact
colA
colB
A
1
A
2
A
3
A
4
A
5
B
1
B
2
B
3
B
5
C
2
C
3
If you have this you can reach where you need by using following measures
Measure3 =
CALCULATE ( COUNTROWS ( _fact ), ALL ( _dim2[colB] ), VALUES ( _fact[colA] ) )
Measure9 =
VAR _1 =
MAX ( _dim2[colB] )
VAR _2 =
CALCULATE (
MAXX (
FILTER ( _dim2, _dim2[colB] <= _1 ),
LASTNONBLANKVALUE ( _dim2[colB], [Measure3] )
),
ALL ( _dim2[colB] )
)
RETURN
_2
Measure10 =
VAR _1 =
MAX ( _dim2[colB] )
VAR _2 =
CALCULATE (
MAXX (
FILTER ( _dim2, _dim2[colB] > _1 ),
FIRSTNONBLANKVALUE ( _dim2[colB], [Measure3] )
),
ALL ( _dim2[colB] )
)
RETURN
IF ( ISBLANK ( [Measure9] ) = TRUE (), _2, [Measure9] )
I don't think you can reach here from a single table like following
colA
colB
A
1
A
2
A
3
A
4
A
5
B
1
B
2
B
3
B
5
C
2
C
3
Continuing with the answer to a previous SO question here, the resulting table is occupying the entire width of a slidy_presentation despite the command kable_styling(full_width=F) being utilized. As I am still new to the kableExtra package and RMarkdown as a whole, I have a feeling it might be due to the long footnote at the bottom of the table.
As a result, I am trying to utilize the HTML "popover" feature as suggested in the R vignette Awesome Table in HTML. In particular, I am trying to create a "Note" field in the last row of the x column from the following .RMD file.
RMD file:
---
title: "Untitled"
output: slidy_presentation
---
```{r}
library(kableExtra)
library(dplyr)
```
Include the HTML script from vignette here.
```{r echo=FALSE}
prob.success <- sample( seq(.5,.99,.01), size=1 )
conf.alpha <- sample( seq(.5,.99,.01), size=1 )
tab1 <- data.frame( x=0:5, f=round(dbinom(0:5,5,prob.success),3) ) %>%
mutate( pe=x/5, lcl=qbeta(1-conf.alpha,x+0.5,5-0:5+0.5) ) %>%
mutate( lcl=pmin(pe,lcl) ) %>%
mutate( delta=pe-lcl ) %>%
mutate( f_delta=f*delta )
exp.expr <- "$\\sum_x f(x)*\\left ( pe(x) - lcl(x) \\right )$"
exp.delta <- format( round(sum( tab1$f_delta ),4), nsmall=4 )
tab2 <- tab1 %>%
mutate( x=as.character(x), f=format(round(f,4),nsmall=4) ) %>%
mutate( pe=format(round(pe,4),nsmall=4) ) %>%
mutate( lcl=format(round(lcl,4),nsmall=4) ) %>%
mutate( delta=format(round(delta,4),nsmall=3) ) %>%
mutate( f_delta=format(round(f_delta,4),nsmall=4) ) %>%
rbind( ., data.frame(x="", f="", pe="Exp", lcl="Diff", delta="=", f_delta=exp.expr) ) %>%
rbind( ., data.frame(x="",f="",pe="",lcl="",delta="=",f_delta=exp.delta) )
tab.cols <- c( "x", "f(x)", "pe(x)", "lcl(x)", "pe(x)-lcl(x)",
"$f(x)\\times\\left(pe(x)-lcl(x)\\right)$" )
kable( tab2, format="html", escape=FALSE, align="c", col.names=tab.cols ) %>%
kable_styling( "striped", full_width = F, position="center" ) %>%
footnote( general="Given x successes out of n trials, the holistic Jeffreys $100*(1-\\alpha)\\%$ Lower *Credible* Limit is the value $p$ such that $\\int_0^p \\frac{t^{x+0.5-1}(1-t)^{n-x+0.5-1}}{B(x+0.5,n-x+0.5)} dt = \\alpha$ where B(a,b) is the Beta function given by $\\int_0^1 t^{(x-1)}(1-t)^{(y-1)} dt$.",
general_title="Note:", footnote_as_chunk=TRUE, escape=FALSE )
My attempt thus far
With the only change to the R chunk above being with the variable tab2, here is what I have tried.
tab2 <- tab1 %>%
mutate( x=as.character(x), f=format(round(f,4),nsmall=4) ) %>%
mutate( pe=format(round(pe,4),nsmall=4) ) %>%
mutate( lcl=format(round(lcl,4),nsmall=4) ) %>%
mutate( delta=format(round(delta,4),nsmall=3) ) %>%
mutate( f_delta=format(round(f_delta,4),nsmall=4) ) %>%
rbind( ., data.frame(x="", f="", pe="Exp", lcl="Diff", delta="=", f_delta=exp.expr) ) %>%
# Change is only with the last line
rbind( ., data.frame(x=cell_spec("Note",popover=spec_popover(content="Test",title=NULL,position="bottom")),
f="",pe="",lcl="",delta="=",f_delta=exp.delta) )
and the popover feature doesn't work.
I've got this data:
Then have this measure:
amount = SUM( play[amount] )
Then I've tried to use the ASC/DESC arguments of the TOPN function in these two measures:
Top 2 customer per category ASC =
VAR rnk = VALUES( play[customer] )
RETURN
CALCULATE(
[amount],
TOPN(
2,
ALL( play[customer] ),
[amount],
ASC
),
RNK
)
Top 2 customer per category DESC =
VAR rnk = VALUES( play[customer] )
RETURN
CALCULATE(
[amount],
TOPN(
2,
ALL( play[customer] ),
[amount],
DESC
),
RNK
)
Now if I use these two measures it looks like the following:
What is going on?
Why is the measure Top 2 customer per category ASC showing nothing?
How do I amend that measure so that it shows values for the bottom two values of each category?
The problem here is that the second argument of TOPN should be a table, not an unfiltered column.
Regardless of what the category is, ALL(play[customer]) returns the table:
customer
--------
xx
yy
zz
jj
qq
ff
The measure [amount] is still evaluated within the category filter context though so for category = "a" you get
customer [amount]
------------------
xx 10
yy 12
zz 13
jj
qq
ff
and for category = "b" you get
customer [amount]
------------------
xx
yy
zz
jj 15
qq 16
ff 9
These blanks are considered smaller than any number so they are what gets selected when you sort ASC.
Try this slightly modified measure instead:
Top 2 customer per category ASC =
VAR rnk = VALUES ( play[customer] )
RETURN
CALCULATE (
[amount],
TOPN ( 2, CALCULATETABLE ( play, ALL ( play[customer] ) ), [amount], ASC ),
RNK
)
Using CALCULATETABLE, the category filter context gets preserved.
P.S. To generate the tables above you can write a new calculated table like this:
Top2Table =
CALCULATETABLE (
ADDCOLUMNS ( ALL ( play[customer] ), "amount", [amount] ),
play[category] = "a" <or "b">
)
I am trying to further develop a formula which has condition as below :
Choose the desired ID, it will look at the Volume value of the Products of that ID and it will multiply that volume value into the x.Value of the same products with different IDs.
Now I want to choose the products, and if an specific ID does not have that particular product I want it to still return the "chosen ID's Product's "X Value" * chosen ID's Product's Volume value and show in my Stack column.
so for example from attached Data set I would like to choose an ID for example 4321, and it contained product that wasn't available in the other ID's , it will choose the X and volume value of 4321 and show us in the stacked columns? So For example, the product E does not exists in the ID 1234 and 5566 so when it is showing us the final numbers with the volume of 4321 in a, B , C it will also return the Product E into them?
here is the previous formula which needs to be further developed and the previous post which is related to this question :
Desired Volume Measure
SUMX (
Table2,
VAR LookupID =
IF (
HASONEVALUE ( 'ID List'[ID ] ),
VALUES ( 'ID List'[ID ] ),
BLANK()
)
VAR LookupProduct =
IF (
HASONEVALUE ( Table2[Product] ),
VALUES ( Table2[Product] ),
BLANK()
)
VAR EffectiveVolume =
CALCULATE (
SUM ( Table2[Volume] ),
ALL ( Table2 ),
Table2[ID ] = LookupID,
Table2[Product] = LookupProduct)
RETURN
(Table2[X.Value]) *
IF (
ISBLANK ( EffectiveVolume ),
Table2[Volume],
EffectiveVolume
)
)
Automated formula to select values from a specifid ID and multiply to the rest with the same Name
I tried adding a condition which I thought might be useful, but unfortunately it doesnt work by adding :
VAR EffectiveXValue =
CALCULATE (
SUM ( Table2[X.Value] ),
ALL ( Table2 ),
Table2[ID ] = LookupID,
Table2[Product] = LookupProduct)
RETURN
IF(ISBLANK(ISFILTERED(Table1[Product])),EffectiveXValue,Table2[X.Value])*
IF (
ISBLANK ( EffectiveVolume ),
Table2[Volume],
EffectiveVolume
)
)
Thanks a Million