Qwraps2- row group label not showing up in summary table - r

Built a summary table, but the labels of the row groups are not showing up.
args(data)
summary1 <- list("Gender"= list("Female"
=~qwraps2::n_perc0(Sex==0, na_rm=TRUE))
table1 <- summary_table(data, summary1)
My table looks like this: table1:
How do I get the "Gender" group name to show-up in the table?

It looks like you are viewing the table in RStuido via double clicking on the table1 in the "Environment" tab. The display is as expected. The structure of the qwraps2_summary_table object is a character matrix. In or outside of RStudio you can get the same result shown in the question post via View(table1).
To see the well rendered html you'll need to knit a .Rmd to html. Or, in RStuido you can upon a "R Notebook." A screen capture of of a simple example from an R Notebook follows:

This may be related to how you "show" your table (You did not write anything about how you got it). When I use qwraps in rmarkdown in edit mode. When I just select the table (in your case table1) and press ctrl + enter I get the result you're asking for. If I use kable(table1) this removes this labelling.
I think the print() function recognized the qwrap table and prints it with the group names.
Ask a minimally reproducible example if you want more help.

Related

Add hyperlinks to cells (and/or rows) of DT table in flexdashboard

I have a large table which I would like to present in interactive (filterable and sortable) form within a flexdashboard. I have achieved this using the DT package. One of the columns contains URLs, which currently are not 'clickable', so users will have to copy and paste into their browser. Is there a way to make these URLs into hyperlinks?
I have tried adding html tags in this format:
Link text
But the tags themselves display in the table, with no hyperlink.
Another related question - as these URLs are taking up a large proportion of the width of the table, is it possible to make an entire row 'clickable', directing users to the URL stored in 'column B' of the table, without displaying 'column B'?
The other answers I have found apply to using DT in JavaScript or shiny, and seem not to match my code.
Thank you :)
You can use escape=FAlSEarguement in datatable() function.
Here is an example:
df <- data.frame(textLink=paste0('Link text'))
datatable(df, escape = FALSE)

RStudio not showing output in Console when using a variable?

Currently learning RStudio but for some reason my Console isn't outputting my code? Not sure if there was a setting I may have toggled but it seems to only affect me when I have a variable in my code?
For example:
when working the ToothGrowth dataset
data("ToothGrowth")
View(ToothGrowth)
This executes and I can view the table of the data in a separate tab.
However, when I try to filter it
data("ToothGrowth")
View(ToothGrowth)
filtered_tg = filter(ToothGrowth, dose=0.5)
View(filtered_tg)
Nothing Returns, a formatted table doesn't open and an empty line is returned in the console window.
This is just one example, even when i try something as simple as
number = 10
number
I would expect, in return;
[1] 10
But console is empty.
Looking for solutions online, I've seen maybe i didn't close a bracket or parenthesis and to include CloseAllConnections() if there was a '+' showing in the console (which there isn't).
Working on rstudio cloud so is there a reset somewhere that I could possibly try?
Thanks for any and all help!
I changed the function as follows:
filtered_tg = filter(ToothGrowth, dose=="0.5")
View(filtered_tg)
After running these commands it was viewed as the table of the data in a separate tab 👇
Output

R View gt table in window from script message box three buttons

Ultimate goal: Display gt table in pop-out window with 3 buttons to control script action
Minimum goal: Display a gt table in pop-out viewer window
Full detail:
I am creating a table using the gt package in R. I want to display the table with three options for how to proceed: OK (script continues), Edit (allow the user to make minor modifications to a specific column), Cancel (something has gone wrong and the process needs to be terminated). My plan is to allow a quick QC of the data before it gets saved. My issue is that I have no idea how to display a gt table in a viewer window or with tk_messageBox and that's about the only package I know of that might do this.
Any ideas?
Here's an example gt table:
table <- gt(mtcars) %>%
tab_header(
title = md("**2014 - 2019 Salary and Playoff Appearances**âš½"),
subtitle = "I am a boss")
you could achieve such an effect with shiny/miniUI specifically runGadget()
see this answer I gave yesterday which is an example where the user is shown two checkboxes to interact with that are returned as data into the calling environment
Is it possible to create a check box to record a user's input without resorting to Shiny in R?

PowerBI: How to save result of R script?

Is it possible to implement the following scenario in Power BI Desktop?
Load data from Excel file to several tables
Make calculation with R script from several data sources
Store results of calculation to new table in Power BI (.pbix)
The idea is to use Power BI Desktop for solving "transportation problem" with linear programming in R. Before solver will be running we need to make data transformations from several data sources. I'm new in Power BI. I see that it is possible to apply R scripts for loading and transformation of data, and visualizations. But I need the possibility of saving the results of calculation, for the subsequent visualization by the regular means of Power BI. Is it possible?
As I mentioned in my comment, this post would have solved most of your challenges. That approach replaces one of the tables with a new one after the R script, but you're specifically asking to produce a new table, presumably leaving the input tables untouched. I've recently written a post where you can do this using Python in the Power Query Editor. The only difference in your case would be the R script itself.
Here's how I would do it with an R script:
Data samples:
Table1
Date,Value1
2108-10-12,1
2108-10-13,2
2108-10-14,3
2108-10-15,4
2108-10-16,5
Table2
Date,Value2
2108-10-12,10
2108-10-13,11
2108-10-14,12
2108-10-15,13
2108-10-16,14
Power Query Editor:
With these tables loaded either from Excel or CSV files, you've got this setup in the Power Query Editor::
Now you can follow these steps to get a new table using an R script:
1. Change the data type of the Date Column to Text
2. Click Enter Data and click OK to get an empty table named Table3 by default.
3. Select the Transform tab and click Run R Script to open the Run R Script Edtor.
4. Leave it empty and click OK.
5. Remove = R.Execute("# 'dataset' holds the input data for this script",[dataset=#"Changed Type"]) from the Formula Bar and insert this: = R.Execute("# R Script:",[df1=Table1, df2=Table2]).
6. If you're promted to do so, click Edit Permission and Run.
7. Click the gear symbol next to Run R Scritp under APPLIED STEPS and insert the following snippet:
R script:
df3 <- merge(x = df1, y = df2, by = "Date", all.x = TRUE)
df3$Value3 <- df1$Value1 + df2$Value2
This snippet produces a new dataframe df3 by joining df1 and df2, and adds a new column Value3. This is a very simple setup but now you can do pretty much anything by just replacing the join and calculation methods:
8. Click Home > Close&Apply to get back to Power BI Desktop (Consider changing the data type of the Date column in Table3 from Text to Date before you do that, depending on how you'd like you tables, charts and slicers to behave.)
9. Insert a simple table to make sure everything went smoothly
I hope this was exactly what you were looking for. Let me know if not and I'll take another look at it.

Is it possible to to export from reporttools?

I am using tableNominal{reporttools} to produce frequency tables. The way I understand it, tableNominal() produces latex code which has to be copied and pasted onto a text file and then saved as .tex. But is it possible to simple export the table produced as can be done in print(xtable(table), file="path/outfile.tex"))?
You may be able to use either latex or latexTranslate from the "Hmisc" package for this purpose. If you have the necessary program infrastructure the output gets sent to your TeX engine. (You may be able to improve the level of our answers by adding specific examples.)
Looks like that function does not return a character vector, so you need to use a strategy to capture the output from cat(). Using the example in the help page:
capture.output( TN <- tableNominal(vars = vars, weights = weights, group = group,
cap = "Table of nominal variables.", lab = "tab: nominal") ,
file="outfile.tex")

Resources