diagrammeR (grViz) 正在从环境中寻找数据,而不是从闪亮的内部值中寻找数据
diagrammeR (grViz) is looking for the data from environment rather than from the values inside shiny
我有下面的图表设置,如果我在环境中有 data
值,图表只能生成下面的图表,它根本不查看我在服务器中指定的数据值。我应该怎么做?
library(DiagrammeR)
library(shiny)
ui <- fluidPage(
grVizOutput("parameter_plot"),
numericInput("some_values", label = "Some values",
value = 1, min = 1, max = 100, step = 1)
)
server <- function(input, output, session) {
# Define some sample data
output$parameter_plot <- renderGrViz({
# Define some sample data
data = tibble(a=1000,b=input$some_values,c=1000,d=1000,e=1000,f=1,g=1,h=1)
DiagrammeR::grViz("
digraph graph2 {
graph [layout = dot]
# node definitions with substituted label text
node [shape = rectangle, style = filled]
node [fillcolor = lightblue]
a [label = '@@1']
node [fillcolor = Beige]
b [label = '@@2']
c [label = '@@3']
d [label = '@@4']
node [fillcolor = mediumpurple1]
e [label = '@@5']
f [label = '@@6']
g [label = '@@7']
node [fillcolor = darkseagreen1]
h [label = '@@8']
i [label = '@@9']
subgraph cluster1 {
node [fixedsize = true, width = 3]
b -> {c d}
}
subgraph cluster2 {
node [fixedsize = true, width = 3]
e -> f -> g -> e
}
subgraph cluster3 {
node [fixedsize = true, width = 3]
h
i
}
a -> b
a -> e
f -> i
e -> h
}
")
})
}
shinyApp(ui, server)
如果您在末尾正确指定了脚注,它应该可以工作。在下面的示例中,我使用 glue::glue
将代码插入到字符串中。 label 1的一部分来自一个data.frame
,label 6的一部分来自一个numericInput
,可以交互调整。
library(DiagrammeR)
library(shiny)
library(dplyr)
library(glue)
ui <- fluidPage(
grVizOutput("parameter_plot"),
numericInput("some_values", label = "Some values",
value = 1, min = 1, max = 100, step = 1)
)
server <- function(input, output, session) {
# Define some sample data
output$parameter_plot <- renderGrViz({
print(input$some_values)
# Define some sample data
data = tibble(a = 696,
b = input$some_values,
c = 1000,
d = 1000,
e = 1000,
f = 1,
g = 1,
h = 1)
DiagrammeR::grViz(glue::glue(
.open = "{{",
.close = "}}",
"digraph graph2 {
graph [layout = dot]
# node definitions with substituted label text
node [shape = rectangle, style = filled]
node [fillcolor = lightblue]
a [label = '@@1']
node [fillcolor = Beige]
b [label = '@@2']
c [label = '@@3']
d [label = '@@4']
node [fillcolor = mediumpurple1]
e [label = '@@5']
f [label = '@@6']
g [label = '@@7']
node [fillcolor = darkseagreen1]
h [label = '@@8']
i [label = '@@9']
subgraph cluster1 {
node [fixedsize = true, width = 3]
b -> {c d}
}
subgraph cluster2 {
node [fixedsize = true, width = 3]
e -> f -> g -> e
}
subgraph cluster3 {
node [fixedsize = true, width = 3]
h
i
}
a -> b
a -> e
f -> i
e -> h
}
[1]: '1. Est.Demand (n = {{data$a}})'
[2]: 'Patient leaves pathway'
[3]: 'NAS: Discharged (n = 78)'
[4]: '2. ROTT (n = 8)'
[5]: '4. Clinical Slots Used (n = 665)'
[6]: 'Some values (n = {{input$some_values}})'
[7]: '7. NASL: Rebooked (n = 55)'
[8]: '6. NASL (n = 14)'
[9]: '8. Expected Attendences (n = 596)'
"))
})
}
shinyApp(ui, server)
我有下面的图表设置,如果我在环境中有 data
值,图表只能生成下面的图表,它根本不查看我在服务器中指定的数据值。我应该怎么做?
library(DiagrammeR)
library(shiny)
ui <- fluidPage(
grVizOutput("parameter_plot"),
numericInput("some_values", label = "Some values",
value = 1, min = 1, max = 100, step = 1)
)
server <- function(input, output, session) {
# Define some sample data
output$parameter_plot <- renderGrViz({
# Define some sample data
data = tibble(a=1000,b=input$some_values,c=1000,d=1000,e=1000,f=1,g=1,h=1)
DiagrammeR::grViz("
digraph graph2 {
graph [layout = dot]
# node definitions with substituted label text
node [shape = rectangle, style = filled]
node [fillcolor = lightblue]
a [label = '@@1']
node [fillcolor = Beige]
b [label = '@@2']
c [label = '@@3']
d [label = '@@4']
node [fillcolor = mediumpurple1]
e [label = '@@5']
f [label = '@@6']
g [label = '@@7']
node [fillcolor = darkseagreen1]
h [label = '@@8']
i [label = '@@9']
subgraph cluster1 {
node [fixedsize = true, width = 3]
b -> {c d}
}
subgraph cluster2 {
node [fixedsize = true, width = 3]
e -> f -> g -> e
}
subgraph cluster3 {
node [fixedsize = true, width = 3]
h
i
}
a -> b
a -> e
f -> i
e -> h
}
")
})
}
shinyApp(ui, server)
如果您在末尾正确指定了脚注,它应该可以工作。在下面的示例中,我使用 glue::glue
将代码插入到字符串中。 label 1的一部分来自一个data.frame
,label 6的一部分来自一个numericInput
,可以交互调整。
library(DiagrammeR)
library(shiny)
library(dplyr)
library(glue)
ui <- fluidPage(
grVizOutput("parameter_plot"),
numericInput("some_values", label = "Some values",
value = 1, min = 1, max = 100, step = 1)
)
server <- function(input, output, session) {
# Define some sample data
output$parameter_plot <- renderGrViz({
print(input$some_values)
# Define some sample data
data = tibble(a = 696,
b = input$some_values,
c = 1000,
d = 1000,
e = 1000,
f = 1,
g = 1,
h = 1)
DiagrammeR::grViz(glue::glue(
.open = "{{",
.close = "}}",
"digraph graph2 {
graph [layout = dot]
# node definitions with substituted label text
node [shape = rectangle, style = filled]
node [fillcolor = lightblue]
a [label = '@@1']
node [fillcolor = Beige]
b [label = '@@2']
c [label = '@@3']
d [label = '@@4']
node [fillcolor = mediumpurple1]
e [label = '@@5']
f [label = '@@6']
g [label = '@@7']
node [fillcolor = darkseagreen1]
h [label = '@@8']
i [label = '@@9']
subgraph cluster1 {
node [fixedsize = true, width = 3]
b -> {c d}
}
subgraph cluster2 {
node [fixedsize = true, width = 3]
e -> f -> g -> e
}
subgraph cluster3 {
node [fixedsize = true, width = 3]
h
i
}
a -> b
a -> e
f -> i
e -> h
}
[1]: '1. Est.Demand (n = {{data$a}})'
[2]: 'Patient leaves pathway'
[3]: 'NAS: Discharged (n = 78)'
[4]: '2. ROTT (n = 8)'
[5]: '4. Clinical Slots Used (n = 665)'
[6]: 'Some values (n = {{input$some_values}})'
[7]: '7. NASL: Rebooked (n = 55)'
[8]: '6. NASL (n = 14)'
[9]: '8. Expected Attendences (n = 596)'
"))
})
}
shinyApp(ui, server)