Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
Radiant
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wuzekai
Radiant
Commits
6392feca
Commit
6392feca
authored
Aug 18, 2026
by
wuzekai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(quickgen): 可视化函数 NULL 安全与 NA 处理改进
parent
4935b39a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
29 deletions
+59
-29
quickgen_basic.R
radiant.quickgen/R/quickgen_basic.R
+39
-6
quickgen_basic_ui.R
radiant.quickgen/inst/app/tools/analysis/quickgen_basic_ui.R
+20
-23
No files found.
radiant.quickgen/R/quickgen_basic.R
View file @
6392feca
...
@@ -461,6 +461,34 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
...
@@ -461,6 +461,34 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
labs
=
list
(),
xlim
=
NULL
,
ylim
=
NULL
,
data_filter
=
""
,
labs
=
list
(),
xlim
=
NULL
,
ylim
=
NULL
,
data_filter
=
""
,
arr
=
""
,
rows
=
NULL
,
shiny
=
FALSE
,
custom
=
FALSE
,
arr
=
""
,
rows
=
NULL
,
shiny
=
FALSE
,
custom
=
FALSE
,
envir
=
parent.frame
())
{
envir
=
parent.frame
())
{
## NULL 安全:Shiny 动态 UI 中未绑定的 input 可能传 NULL,统一回退到默认值
if
(
is.null
(
comby
))
comby
<-
FALSE
if
(
is.null
(
combx
))
combx
<-
FALSE
if
(
is.null
(
custom
))
custom
<-
FALSE
if
(
is.null
(
shiny
))
shiny
<-
FALSE
if
(
is.null
(
yvar
))
yvar
<-
""
if
(
is.null
(
check
))
check
<-
""
if
(
is.null
(
axes
))
axes
<-
""
if
(
is.null
(
color
))
color
<-
"none"
if
(
is.null
(
fill
))
fill
<-
"none"
if
(
is.null
(
size
))
size
<-
"none"
if
(
is.null
(
facet_row
))
facet_row
<-
"."
if
(
is.null
(
facet_col
))
facet_col
<-
"."
if
(
is.null
(
nrobs
))
nrobs
<-
-1
if
(
is.null
(
fun
))
fun
<-
"mean"
if
(
is.null
(
data_filter
))
data_filter
<-
""
if
(
is.null
(
arr
))
arr
<-
""
if
(
is.null
(
alpha
))
alpha
<-
0.5
if
(
is.null
(
bins
))
bins
<-
10
if
(
is.null
(
smooth
))
smooth
<-
1
if
(
is.null
(
fillcol
))
fillcol
<-
"blue"
if
(
is.null
(
linecol
))
linecol
<-
"black"
if
(
is.null
(
pointcol
))
pointcol
<-
"black"
if
(
is.null
(
theme
))
theme
<-
"theme_gray"
if
(
is.null
(
base_size
))
base_size
<-
11
if
(
is.null
(
base_family
))
base_family
<-
""
if
(
is.null
(
labs
))
labs
<-
list
()
if
(
missing
(
xvar
)
&&
type
%in%
c
(
"box"
,
"line"
))
{
if
(
missing
(
xvar
)
&&
type
%in%
c
(
"box"
,
"line"
))
{
xvar
<-
yvar
xvar
<-
yvar
if
(
type
==
"box"
)
{
if
(
type
==
"box"
)
{
...
@@ -537,7 +565,8 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
...
@@ -537,7 +565,8 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
## so you can also pass-in a data.frame
## so you can also pass-in a data.frame
df_name
<-
if
(
is_string
(
dataset
))
dataset
else
deparse
(
substitute
(
dataset
))
df_name
<-
if
(
is_string
(
dataset
))
dataset
else
deparse
(
substitute
(
dataset
))
dataset
<-
get_data
(
dataset
,
vars
,
filt
=
data_filter
,
arr
=
arr
,
rows
=
rows
,
envir
=
envir
)
dataset
<-
get_data
(
dataset
,
vars
,
filt
=
data_filter
,
arr
=
arr
,
rows
=
rows
,
envir
=
envir
,
na.rm
=
!
type
%in%
c
(
"dist"
,
"density"
))
if
(
type
==
"scatter"
&&
!
is.empty
(
nrobs
))
{
if
(
type
==
"scatter"
&&
!
is.empty
(
nrobs
))
{
nrobs
<-
as.integer
(
nrobs
)
nrobs
<-
as.integer
(
nrobs
)
...
@@ -715,10 +744,13 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
...
@@ -715,10 +744,13 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
dc
[
i
]
<-
"factor"
dc
[
i
]
<-
"factor"
}
}
## 每个子图独立剔除自身字段的 NA 行(多字段时缺失行不重叠也不会互相影响)
ds_i
<-
dataset
[
!
is.na
(
dataset
[[
i
]]),
,
drop
=
FALSE
]
hist_par
<-
list
(
alpha
=
alpha
,
position
=
"stack"
)
hist_par
<-
list
(
alpha
=
alpha
,
position
=
"stack"
)
if
(
combx
)
hist_par
[[
"position"
]]
<-
"identity"
if
(
combx
)
hist_par
[[
"position"
]]
<-
"identity"
if
(
fill
==
"none"
)
hist_par
[[
"fill"
]]
<-
fillcol
if
(
fill
==
"none"
)
hist_par
[[
"fill"
]]
<-
fillcol
plot_list
[[
i
]]
<-
ggplot
(
d
ataset
,
aes
(
x
=
.data
[[
i
]]))
plot_list
[[
i
]]
<-
ggplot
(
d
s_i
,
aes
(
x
=
.data
[[
i
]]))
if
(
"density"
%in%
axes
&&
!
"factor"
%in%
dc
[
i
])
{
if
(
"density"
%in%
axes
&&
!
"factor"
%in%
dc
[
i
])
{
hist_par
<-
c
(
list
(
aes
(
y
=
after_stat
(
density
))),
hist_par
)
hist_par
<-
c
(
list
(
aes
(
y
=
after_stat
(
density
))),
hist_par
)
plot_list
[[
i
]]
<-
plot_list
[[
i
]]
+
geom_density
(
adjust
=
smooth
,
color
=
linecol
,
linewidth
=
.5
)
plot_list
[[
i
]]
<-
plot_list
[[
i
]]
+
geom_density
(
adjust
=
smooth
,
color
=
linecol
,
linewidth
=
.5
)
...
@@ -728,8 +760,8 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
...
@@ -728,8 +760,8 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
if
(
"log_x"
%in%
axes
)
axes
<-
sub
(
"log_x"
,
""
,
axes
)
if
(
"log_x"
%in%
axes
)
axes
<-
sub
(
"log_x"
,
""
,
axes
)
}
else
{
}
else
{
plot_fun
<-
get
(
"geom_histogram"
)
plot_fun
<-
get
(
"geom_histogram"
)
hist_par
[[
"binwidth"
]]
<-
select_at
(
d
ataset
,
.vars
=
i
)
%>%
hist_par
[[
"binwidth"
]]
<-
select_at
(
d
s_i
,
.vars
=
i
)
%>%
range
()
%>%
range
(
na.rm
=
TRUE
)
%>%
{
{
diff
(
.
)
/
(
bins
-
1
)
diff
(
.
)
/
(
bins
-
1
)
}
}
...
@@ -740,7 +772,8 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
...
@@ -740,7 +772,8 @@ visualize <- function(dataset, xvar, yvar = "", comby = FALSE, combx = FALSE,
}
}
}
else
if
(
type
==
"density"
)
{
}
else
if
(
type
==
"density"
)
{
for
(
i
in
xvar
)
{
for
(
i
in
xvar
)
{
plot_list
[[
i
]]
<-
ggplot
(
dataset
,
aes
(
x
=
.data
[[
i
]]))
+
ds_i
<-
dataset
[
!
is.na
(
dataset
[[
i
]]),
,
drop
=
FALSE
]
plot_list
[[
i
]]
<-
ggplot
(
ds_i
,
aes
(
x
=
.data
[[
i
]]))
+
if
(
fill
==
"none"
)
{
if
(
fill
==
"none"
)
{
geom_density
(
adjust
=
smooth
,
color
=
linecol
,
fill
=
fillcol
,
alpha
=
alpha
,
linewidth
=
1
)
geom_density
(
adjust
=
smooth
,
color
=
linecol
,
fill
=
fillcol
,
alpha
=
alpha
,
linewidth
=
1
)
}
else
{
}
else
{
...
...
radiant.quickgen/inst/app/tools/analysis/quickgen_basic_ui.R
View file @
6392feca
...
@@ -90,13 +90,14 @@ qib_args <- as.list(formals(visualize))
...
@@ -90,13 +90,14 @@ qib_args <- as.list(formals(visualize))
## 收集用户输入的 reactive 列表
## 收集用户输入的 reactive 列表
qgb_inputs
<-
reactive
({
qgb_inputs
<-
reactive
({
qgb_args
$
data_filter
<-
if
(
i
nput
$
show_filter
)
input
$
data_filter
else
""
qgb_args
$
data_filter
<-
if
(
i
sTRUE
(
input
$
show_filter
)
)
input
$
data_filter
else
""
qgb_args
$
arr
<-
if
(
i
nput
$
show_filter
)
input
$
data_arrange
else
""
qgb_args
$
arr
<-
if
(
i
sTRUE
(
input
$
show_filter
)
)
input
$
data_arrange
else
""
qgb_args
$
rows
<-
if
(
i
nput
$
show_filter
)
input
$
data_rows
else
""
qgb_args
$
rows
<-
if
(
i
sTRUE
(
input
$
show_filter
)
)
input
$
data_rows
else
""
qgb_args
$
dataset
<-
input
$
dataset
qgb_args
$
dataset
<-
input
$
dataset
for
(
i
in
r_drop
(
names
(
qgb_args
)))
{
for
(
i
in
r_drop
(
names
(
qgb_args
)))
{
qgb_args
[[
i
]]
<-
input
[[
paste0
(
"qgb_"
,
i
)]]
val
<-
input
[[
paste0
(
"qgb_"
,
i
)]]
qgb_args
[[
i
]]
<-
if
(
is.null
(
val
))
formals
(
explore
)[[
i
]]
else
val
}
}
qgb_args
qgb_args
})
})
...
@@ -112,10 +113,14 @@ qib_inputs <- reactive({
...
@@ -112,10 +113,14 @@ qib_inputs <- reactive({
qib_args
$
arr
<-
if
(
isTRUE
(
input
$
show_filter
))
input
$
data_arrange
else
""
qib_args
$
arr
<-
if
(
isTRUE
(
input
$
show_filter
))
input
$
data_arrange
else
""
qib_args
$
rows
<-
if
(
isTRUE
(
input
$
show_filter
))
input
$
data_rows
else
""
qib_args
$
rows
<-
if
(
isTRUE
(
input
$
show_filter
))
input
$
data_rows
else
""
qib_args
$
dataset
<-
input
$
dataset
qib_args
$
dataset
<-
input
$
dataset
qib_args
$
shiny
<-
i
nput
$
shiny
qib_args
$
shiny
<-
i
sTRUE
(
input
$
shiny
)
qib_args
$
labs
<-
qib_add_labs
()
qib_args
$
labs
<-
qib_add_labs
()
for
(
i
in
r_drop
(
names
(
qib_args
),
drop
=
c
(
i
18
n
$
t
(
"dataset"
),
i
18
n
$
t
(
"data_filter"
),
i
18
n
$
t
(
"arr"
),
i
18
n
$
t
(
"rows"
),
i
18
n
$
t
(
"labs"
))))
{
## 使用英文参数名做 drop(formals 名称始终是英文),避免 i18n 翻译后匹配失败导致参数被 NULL 覆盖
qib_args
[[
i
]]
<-
input
[[
paste0
(
"qib_"
,
i
)]]
drop_params
<-
c
(
"dataset"
,
"data_filter"
,
"arr"
,
"rows"
,
"shiny"
,
"labs"
,
"envir"
)
for
(
i
in
r_drop
(
names
(
qib_args
),
drop
=
drop_params
))
{
val
<-
input
[[
paste0
(
"qib_"
,
i
)]]
## 没有对应 UI 的 input 为 NULL,回退到 formals 默认值,防止传给 visualize 的参数为 NULL 导致错误
qib_args
[[
i
]]
<-
if
(
is.null
(
val
))
formals
(
visualize
)[[
i
]]
else
val
}
}
qib_args
qib_args
})
})
...
@@ -812,14 +817,12 @@ output$qib_chart <- renderPlot(
...
@@ -812,14 +817,12 @@ output$qib_chart <- renderPlot(
)
)
}
}
}
}
.qib_chart
()
%>%
p
<-
.qib_chart
()
(
function
(
x
)
{
if
(
is.empty
(
p
)
||
is.character
(
p
))
{
if
(
is.empty
(
x
)
||
is.character
(
x
))
{
plot
(
x
=
1
,
type
=
"n"
,
main
=
paste0
(
"\n"
,
p
),
axes
=
FALSE
,
xlab
=
""
,
ylab
=
""
,
cex.main
=
.9
)
plot
(
x
=
1
,
type
=
"n"
,
main
=
paste0
(
"\n"
,
x
),
axes
=
FALSE
,
xlab
=
""
,
ylab
=
""
,
cex.main
=
.9
)
}
else
if
(
length
(
p
)
>
0
)
{
}
else
if
(
length
(
x
)
>
0
)
{
print
(
p
)
print
(
x
)
}
}
})
},
},
width
=
qib_plot_width
,
width
=
qib_plot_width
,
height
=
qib_plot_height
,
height
=
qib_plot_height
,
...
@@ -841,21 +844,15 @@ output$qib_chart <- renderPlot(
...
@@ -841,21 +844,15 @@ output$qib_chart <- renderPlot(
return
()
return
()
}
}
##
waiting for comby and/or combx to be updated
##
校验 comby/combx 状态(NULL 安全:checkbox 未绑定时视为 FALSE,不再中断绘图)
if
(
input
$
qib_type
%in%
c
(
"dist"
,
"density"
))
{
if
(
input
$
qib_type
%in%
c
(
"dist"
,
"density"
))
{
if
(
isTRUE
(
input
$
qib_comby
))
{
if
(
isTRUE
(
input
$
qib_comby
))
{
return
()
return
()
}
}
if
(
length
(
input
$
qib_xvar
)
>
1
&&
is.null
(
input
$
qib_combx
))
{
return
()
}
}
else
{
}
else
{
if
(
isTRUE
(
input
$
qib_combx
))
{
if
(
isTRUE
(
input
$
qib_combx
))
{
return
()
return
()
}
}
if
(
length
(
input
$
qib_yvar
)
>
1
&&
is.null
(
input
$
qib_comby
))
{
return
()
}
}
}
#req(!is.null(input$qib_color) || !is.null(input$qib_fill))
#req(!is.null(input$qib_color) || !is.null(input$qib_fill))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment