根据 R 中的选择输入值更改图表

Change chart based on selectinput value in R

我已将 window 分成两部分。在这两个部分,我都有一个下拉列表和一个旭日图。现在我想用下拉菜单改变旭日形。我有像 data_pie 和 data_pie2 这样的数据框,这应该从下拉值中更改。我知道我应该使用反应函数,但我不知道如何更改数据帧。

server.R

  output$sunburst <- renderSunburst({sunburst(data_pie, count =  TRUE, legend = list(w = 150,h = 50, s = 15 , t = 1 ), breadcrumb = list(w = 150,h = 75, s = 15 , t = 10))})

  output$sunburst2 <- renderSunburst({sunburst(data_pie2, count =  TRUE, legend = list(w = 150,h = 50, s = 15 , t = 1 ), breadcrumb = list(w = 150,h = 75, s = 15 , t = 10))})

ui.R

tabItem(tabName = "sunbrust",
        h2("Sunbrust Visualization"),
        fluidRow(

          box(
            selectInput("input_pie_links", choices = c("Model 1", "Model 2", "Model 3"), label = "Model Auswahl"),
            sunburstOutput("sunburst", width = "1200", height = "1200")),

          box(
            selectInput("input_pie_rechts", choices = c("Model 1", "Model 2", "Model 3"), label = "Model Auswahl"),
            sunburstOutput("sunburst2", width = "1200", height = "1200"))

我不确定你想做什么。使用 slideInput 选择数据集只显示一个图表而不是两个?也许下面的代码有帮助。如果不是,请说明您正在尝试做什么,并提供更多代码以便您的仪表板可以被复制。

ui.R

  tabItem(tabName = "sunbrust",
               h2("Sunbrust Visualization"),
               fluidRow(

                 box(
                   selectInput("input_pie", choices = c("Model 1" = 1, "Model 2" = 2),
                               label = "Model Auswahl"),
                   sunburstOutput("sunburst", width = "1200", height = "1200"))
               )

server.R

    data = reactive({

    if (input$input_pie == 1) {
      data <- data_pie
    } else {
        data <- data_pie2
      } 

    })

    output$sunburst <- renderSunburst({sunburst(data(), count =  TRUE, legend = list(w = 150,h = 50, s = 15 , t = 1 ), breadcrumb = list(w = 150,h = 75, s = 15 , t = 10))})

我创建了以下解决方案:

ui.R

tabItem(tabName = "sunbrust",
        h2("Sunbrust Visualization"),
        fluidRow(
          #column(10, align="center",
          #       sunburstOutput("sunburst", width = "1200", height = "1200")

      box(
        uiOutput("sunburst_auswahl_links"),
        sunburstOutput("sunburst", width = "1200", height = "1200")),

      box(
        uiOutput("sunburst_auswahl_rechts"),
        sunburstOutput("sunburst2", width = "1200", height = "1200"))

    )

server.R

  output$sunburst_auswahl_links <- renderUI({
    selectInput("auswahl_sunburst_links", "Model Auswahl:", c(1,2,3)) 
  })

  sunbrylinks <- reactive({sunburst(datapielist[as.integer(input$auswahl_sunburst_links)][[1]], count =  TRUE, legend = list(w = 150,h = 50, s = 15 , t = 1 ), breadcrumb = list(w = 150,h = 75, s = 15 , t = 10))})

  output$sunburst <- renderSunburst({sunbrylinks()})


  output$sunburst_auswahl_rechts <- renderUI({
    selectInput("auswahl_sunburst_rechts", "Model Auswahl:", c(1,2,3)) 
  })

  sunbryrechts <- reactive({sunburst(datapielist[as.integer(input$auswahl_sunburst_rechts)][[1]], count =  TRUE, legend = list(w = 150,h = 50, s = 15 , t = 1 ), breadcrumb = list(w = 150,h = 75, s = 15 , t = 10))})

  output$sunburst2 <- renderSunburst({sunbryrechts()})