gpt4 book ai didi

Assistance in data filtering using Shiny App(使用闪亮的App帮助进行数据过滤)

转载 作者:bug小助手 更新时间:2023-10-25 12:00:45 25 4
gpt4 key购买 nike



I have a table that summarizes ~100 clinical trials. This table needs to be added to a shiny app and then the user filter the table based on the different variables in the table like endpoint, intervention, etc.

我有一个表格,总结了大约100项临床试验。这个表需要添加到一个闪亮的应用程序中,然后用户根据表中的不同变量(如端点、干预等)来筛选表。


The problem with that the table is that every study, as far as I know, has to be in only one row. But in excel, each study needs more than one row since variables like "Intervention" and "Endpoint" has so many levels, and I will need to subset on my data based on these variables.

据我所知,这张表格的问题是,每一项研究都必须只排在一行。但在EXCEL中,每个研究都需要不止一行,因为像“干预”和“终点”这样的变量有很多级别,我需要根据这些变量对我的数据进行子集。


For example, user choose to subset on studies that included outcome 1 or maybe intervention 1. Many studies has a mix of these, as in the screenshot below.

例如,用户选择包含结果1或干预1的研究的子集。许多研究混合了这两种方法,如下面的截图所示。


This makes it impossible for each study to fit in one row especially that a study can have up to 15 different interventions (there is a long list of interventions that the use will subset based on)

这使得每项研究不可能放在一行中,特别是一项研究可以有多达15种不同的干预措施(有一长串干预措施将基于使用的子集)。


How to approach this?

如何处理这一问题?


sample


更多回答

(1) It looks like you are having difficulty dealing with that data, period, which means that asking first about shiny-integration is too soon. Solve the basic data problem first, then try to make it fancy/interactive. (2) Please do not post (only) an image of code/data/errors: it breaks screen-readers and it cannot be copied or searched (ref: meta.stackoverflow.com/a/285557 and xkcd.com/2116). Please include the code, console output, or data (e.g., data.frame(...) or the output from dput(head(x))) directly into a code block.

(1)看起来你在处理这些数据方面有困难,句号,这意味着首先询问闪亮的集成太快了。首先解决基本的数据问题,然后试着让它变得花哨/交互。(2)请不要(仅)发布代码/数据/错误的图像:它会破坏屏幕阅读器,并且无法复制或搜索(参见:meta.stackoverflow.com/a/285557和xkcd.com/2116)。请包括代码、控制台输出或数据(例如,data.Frame(...)或从数据输出(HEAD(X)直接进入码块。

优秀答案推荐


It sounds like you need to figure out how to "fill in" all of the empty rows with the preceding row's data. Ignoring the component for now, if I have data (in xlsx, though it doesn't matter if CSV) like the following:

听起来您需要弄清楚如何用前一行的数据“填充”所有空行。现在先忽略闪亮的组件,如果我有如下数据(在xlsx中,但如果是csv并不重要):


spreadsheet with sparse rows


We can read in and fix with zoo::na.locf or tidyr::fill:

我们可以读入并修复zoo::na.locf或tidyr::Fill:


dat <- readxl::read_excel("~/Downloads/something.xlsx")
dat
# # A tibble: 6 × 5
# Author Year Methodology `Intervention(s)` `Endpoint(s)`
# <chr> <dbl> <chr> <chr> <chr>
# 1 X et al. 2022 Prospective Intervention 1 Endpoint 1
# 2 NA NA NA Intervention 2 Endpoint 2
# 3 NA NA NA Intervention 3 Endpoint 3
# 4 Y et al. 2021 Something else Intervention 4 Endpoint 4
# 5 NA NA NA Intervention 5 Endpoint 5
# 6 NA NA NA Intervention 6 Endpoint 6

and fix with one of the following:

并使用以下选项之一进行修复:


tidyr::fill(dat, Author, Year, Methodology)
# # A tibble: 6 × 5
# Author Year Methodology `Intervention(s)` `Endpoint(s)`
# <chr> <dbl> <chr> <chr> <chr>
# 1 X et al. 2022 Prospective Intervention 1 Endpoint 1
# 2 X et al. 2022 Prospective Intervention 2 Endpoint 2
# 3 X et al. 2022 Prospective Intervention 3 Endpoint 3
# 4 Y et al. 2021 Something else Intervention 4 Endpoint 4
# 5 Y et al. 2021 Something else Intervention 5 Endpoint 5
# 6 Y et al. 2021 Something else Intervention 6 Endpoint 6

dat[] <- lapply(dat, zoo::na.locf)
dat
# # A tibble: 6 × 5
# Author Year Methodology `Intervention(s)` `Endpoint(s)`
# <chr> <dbl> <chr> <chr> <chr>
# 1 X et al. 2022 Prospective Intervention 1 Endpoint 1
# 2 X et al. 2022 Prospective Intervention 2 Endpoint 2
# 3 X et al. 2022 Prospective Intervention 3 Endpoint 3
# 4 Y et al. 2021 Something else Intervention 4 Endpoint 4
# 5 Y et al. 2021 Something else Intervention 5 Endpoint 5
# 6 Y et al. 2021 Something else Intervention 6 Endpoint 6

From here, you can filter however you need without losing information on the author/year/etc.

在这里,您可以根据需要进行筛选,而不会丢失有关作者/年份/等的信息。


更多回答

This is great solution. But when we present the final table in a shiny app, each study will be repeated multiple times. For example X et al., according to your table will be present three times. How to avoid this?

这是一个很好的解决方案。但当我们在一个闪亮的应用程序中展示最终的表格时,每项研究都会重复多次。比如X等人,根据你的桌子会出现三次。如何避免这种情况?

I think you need to consider the difference between data "to work on" and data "rendered for aesthetics". I think the latter is what you're talking about is rendering, which can be handled well with packages like gt or DT, perhaps. However, a quick hack might be something like dat[,1:3] <- lapply(dat[,1:3], function(z) ifelse(c(FALSE, z[-length(z)] == z[-1]), "", z)) (where 1:3 are the columns you want to "deduplicate").

我认为您需要考虑“要处理的”数据和“为美观而呈现”的数据之间的区别。我认为后一种情况就是您所说的渲染,这可能可以用GT或DT这样的包很好地处理。但是,快速修改可能类似于dat[,1:3]<-lApply(dat[,1:3],Function(Z)if Else(c(False,z[-Long(Z)]==z[-1]),“”,z))(其中1:3是您想要“删除重复数据”的列)。

Can you give me an example of how this can be implemented in Shiny? I tried this code but didn't show the results. Thank you so much for your help.

你能给我举个例子,说明这一点如何在SHINY中实现吗?我尝试了此代码,但没有显示结果。非常感谢你的帮助。

This has nothing to do with shiny. If you can do this on a console, you can do it in shiny. If you don't know how to put this into a reactive component of a shiny app, then I suggest you step through shiny tutorials to learn about reactivity, such as mastering-shiny.org/basic-reactivity.html.

这跟闪亮一点关系都没有。如果你可以在游戏机上做到这一点,那么你就可以在闪亮中做到这一点。如果你不知道如何将这一点放到一个闪亮的应用程序的反应性组件中,那么我建议你通过闪亮的教程来了解反应性,比如master-shiny.org/basic-reactivity.html。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com