我尝试根据单选按钮 input 的值显示径向网络或对角网络(使用包networkD3param_type_graph
) 。我试图在我的 renderUI() 函数中添加一些 if 语句,但显然它不起作用。闪亮的应用程序就在那里。它仅适用于径向外壳。请使用以下输入测试应用程序:第一个输入:“ petrus ”;第二个输入:' WinesAndCo ',然后点击最后一个蓝色按钮提交。
用户界面
ui <- fluidPage(
# Application title
titlePanel("Carrefour Hierarchical Exploration"),
sidebarLayout(
# Sidebar with a slider input
sidebarPanel(
textInput("param_caption", "Rechercher une famille de vin : ", "petrus"),
radioButtons("param_sites", "Choisis sur quel site",
c("Auchan" = "1",
"G.V.P." = "2",
"Lavinia" = "3",
"Millesima" = "4",
"Vinatis"="5",
"WinesAndCo"="6")),
radioButtons("param_typegraph", "Type de Graphique",
c("Radial Network" = "rad",
"Diagonal Network" = "diag"
)),
sliderInput("param_height", "Graph Height:",
min = 300, max = 3000, value = 300
),
sliderInput("param_width", "Graph Width:",
min = 400, max = 4000, value = 400
),
sliderInput("param_size", "Police Size:",
min = 10, max = 60, value = 10
),
actionButton(inputId="param_go",label="Submit",style="color: #fff; background-color: #337ab7; border-color: #2e6da4")
),
# Show a plot of the generated distribution
mainPanel(
uiOutput('mygraph')
)
)
)
服务器
server <- function(input, output) {
# a lot of compution ... that I do not display
# ...
output$graphresdiag <- renderDiagonalNetwork({
diagonalNetwork (tree_to_display(),height = input$param_height,width = input$param_width, fontSize = input$param_size)
})
output$graphresrad <- renderRadialNetwork({
radialNetwork (tree_to_display(),height = input$param_height,width = input$param_width, fontSize = input$param_size)
})
output$mygraph= renderUI({
if (isolate(input$param_typegraph)=="diag")
{diagonalNetworkOutput(outputId = "graphresdiag",
width = paste0(input$param_width,"px"),
height =paste0(input$param_height,"px") )}
if (isolate(input$param_typegraph)=="rad")
{radialNetworkOutput(outputId = "graphresrad",
width = paste0(input$param_width,"px"),
height =paste0(input$param_height,"px") )}
})
}
你会怎么做才能让它发挥作用?