【问题标题】:How to make a reactive radarchart in Shiny如何在 Shiny 中制作反应式雷达图
【发布时间】:2020-09-12 08:38:49
【问题描述】:

为了研究,我正在研究雷达图的可视化。由于我的研究中有各种主题要包含,我希望有一个使用 Shiny 的反应式雷达图,其中“读者”可以从几行值中选择他们想要在雷达图中看到的内容。但是,我无法做到这一点。

我的数据框如下所示:

       Power      Alliances     National Interest
max     40           40             40
min      0            0              0
lib      4            6             30
left     1           15             10

因为我希望能够在 libleft 之间选择作为我的反应式闪亮雷达图中的变量,并让雷达图本身由 权力联盟国家利益,我创建了以下代码:

ui <- shinyUI(fluidPage(

  # Application title
  titlePanel("Political Parties"),

  sidebarPanel(
    selectInput(
      inputId = "left_lib",
      label = "Argument_Type",
      choices = list("New_Left_Green"="left", "Liberal"="lib")
    )
  ),
  fluidRow(column(12,plotOutput("radarPlot"))
  )))

server <- shinyServer(function(input, output) {
  output$radarPlot <- renderPlot({

    req(input$left_lib)
    radarchart(input$left_lib,
               seg=6,
              title = "New Left / Green versus Liberal in The Netherlands",
              pcol=colors_line,
              plwd=2)
    legend(x=1.6,
           y=1.35,
           legend = rownames(left_lib[-c(1,2),]),
           bty = "n", pch=20, col=colors_line, cex=1.2, pt.cex = 3)
})})

shinyApp(ui = ui, server = server)

雷达图已创建,但它不会对在侧面板中选择 libleft 做出反应。我该如何解决这个问题?

提前谢谢你。

【问题讨论】:

    标签: plot graph server shiny radar-chart


    【解决方案1】:

    您尚未向我们提供您的 radarChart() 函数,因此我无法确定,但我猜您想在代码中的某处将 sliderInput 的值替换为 ID left_lib .为此,您需要在服务器代码中使用input$left_lib 而不是lib_left

    您可能需要在 output$radarPlot 响应式的开头添加 req(input$left_lib) 以防止在未为 input$lib_left 分配值时出现问题。

    顺便说一句,由于当前编写的代码,input$left_lib 的值将是 "New_Left_Green""Liberal"。如果您想在代码中使用值 "left""lib" 但仍向用户显示当前文本,则应使用

    choices = list("New_Left_Green"="left", "Liberal"="lib")

    sliderInput的定义中。

    【讨论】:

    • 感谢您的回答!我确实包含了radarchartfunction - 它位于代码的服务器部分。我在原始答案中编辑了您的评论。但是,Shiny 服务器现在报告我需要一个数据框作为输入。通过使用 input$left_lib,显然它不再将其识别为数据框。你知道有没有办法解决这个问题?提前谢谢!
    • 仍在努力,但无法解决问题。
    • 你有没有想过这个问题?我现在在 Shiny 中也遇到了 Radarcharts 的问题,我怀疑这可能是类似的问题
    猜你喜欢
    • 2021-09-04
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    相关资源
    最近更新 更多