change na using a slider as a table range

...change na using a slider as a table range
I am applying shiny code along with tidyverse, the code I want to make is from a data frame file, select a range with a slider and that at this range I change the na values to a value and show it in a table

library(shiny)
library(tidyverse)
library(dplyr)

a <- read.csv("C:/Users/danyu/OneDrive/Documents/R/b.txt", sep=",", header=TRUE,na = c("", "NA"),
              stringsAsFactors = FALSE)



ui <- fluidPage(
  fluidRow(
    
    column(4,
           
           sliderInput("slider2", label = h3("Slider Range"), step=1, min = 1,
                       max = nrow(a), value = c(1,max))
    )
  ),
  
  hr(),
  
  fluidRow(
    column(4, tableOutput("range"))
  )
  
)

SERVER

server <- function(input, output) {
  a <- read.csv("C:/Users/danyu/OneDrive/Documents/R/b.txt", sep=",", header=TRUE,na = c("", "NA"),
                stringsAsFactors = FALSE)
  mt <- reactive({
    mmmmtttt<- mutate(a,
                      codigo = replace_na(a[input$slider2[1]:input$slider2[2],codigo],666))
  })
  
  
  output$range <- renderTable({
    mt()
  })
  
 
  
}

shinyApp(ui, server)

Hi @DiegoVilla. I would change the reactive expression mt as follow.

  mt <- reactive({
    mutate(a, codigo = `[<-`(codigo, input$slider2[1]:input$slider2[2], replace_na(codigo[input$slider2[1]:input$slider2[2]], 666)))
  })

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.