R shiny 中 while 循环的交互性

问题描述 投票:0回答:0

我创建了一个 while 循环来解决闪亮脚本中的问题,但是当我想让它具有交互性时,它不起作用。

为了简化我的问题,我将用一个简化的数据集来描述它。

我的server.R看起来是这样的,这里代码的目标是当字段RJV对应于'J1'时,将字段or_gestion的所有值替换为'AMEL'。然后存在 while 循环以逐行填充字段 or_gestion 以根据滑块的值增加值“REG”的存在。

library(tidyverse)
library(shiny)
library(sf)

function(input, output, session) {

uex <- reactive({
    uex$or_gestion[uex$RJV == "J1"] <- "AMEL"

    v <- 0
    while (v == input$renouvellement) {
      uex <- uex %>%
        mutate(count = ifelse(RJV=="J1", seq.int(1:nrow(uex)), NA)) %>% 
        group_by(RJV) %>%
        arrange(Priorite_renouv, area)
      uex$or_gestion[uex$or_gestion == "AMEL" & uex$count == v] <- "REG"
      v <- v+1
    }
    
  })

  output$GestionPlot <- renderPlot({
    plot(uex()["or_gestion"], main="Orientation de gestion")
    
  })
}

我想用 while 循环修改 or_gestion 字段,这样当我们更改闪亮的滑块以增加或减少 or_gestion 字段中的“REG”速率时,地图会更新为正确的值。

我的 ui.R 看起来像这样,

library(shiny)

fluidPage(
     navbarPage(
           tabPanel("Scenario de gestion (Libre)",
                  sidebarLayout(
                     sidebarPanel(
                      sliderInput("renouvellement", min = 1, max = 100, value = 1, step = 1, round = 0),
                         ),
                   
        mainPanel(
          plotOutput("GestionPlot"),
          )
        ),
        ),
),
)

我的数据(uex)看起来像这样,

RJV or_gestion 面积 Priorite_renouv 计数
V JEU 5
V JEU 8
R JEU 9
R JEU 15
J1 注册 10 2 2
J1 阿梅尔 20 1 1
J1 阿梅尔 30 2 3
J2 阿梅尔 4
J2 注册 18
J3 JEU 29

当我执行这段代码时,出现错误: min(x) 中的警告:min 没有非缺失参数;返回信息 max(x) 中的警告:max 没有非缺失参数;返回-Inf 警告:plot.window 中的错误:'xlim' 需要有限值

提前感谢您的建议和解决方案! 注意:抱歉我的英语不是我的母语 ;)

r shiny
© www.soinside.com 2019 - 2024. All rights reserved.