0

I am new to Shiny and I am not sure why I get an error.

I already have created a function that takes an input a variable "name" and then after some lines I simply end by print(plot 1) print(plot 2). Now I want to make this function reactive using shiny.

I have already in my R session environment run the dataframe & the function. Then I run the shiny app using this code but I get this error. Do you have any idea what could be the issue? :/

Warning: Error in seq.int: 'to' must be a finite number

library(shiny)

ui <- fluidPage(
  headerPanel("Change graph"), 
  sidebarPanel(
    selectInput(
      "playlist", "Select a Playlist Name", playlist_names)
    ),
  mainPanel(plotOutput("plot1"))
  
  
)

server <- function(input, output) {
  output$plot1<-renderPlot({playlist_name_plots("input$playlist")})
}


shinyApp(ui = ui, server = server)
  • 1
    Welcome to SO! To help us to help you could you please make your issue reproducible? See [how to make a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – stefan Jun 13 '21 at 16:40
  • ... at least I would try `playlist_name_plots(input$playlist)` without quotes. – stefan Jun 13 '21 at 16:41
  • That was the issue, I removed the quotes and it worked! Thanks a lot! – Angeliki Dask Jun 13 '21 at 18:12

1 Answers1

0

You need to specify what's in playlist_names passed as choices = , quoted from ?selectinput:

List of values to select from. If elements of the list are named, then that name — rather than the value — is displayed to the user. It's also possible to group related inputs by providing a named list whose elements are (either named or unnamed) lists, vectors, or factors. In this case, the outermost names will be used as the group labels (leveraging the HTML tag) for the elements in the respective sublist. See the example section for a small demo of this feature.

Working example:

library(shiny)

playlist_names <- c("Playlist A","Playlist B","Playlist C")

ui <- fluidPage(
  headerPanel("Change graph"), 
  sidebarPanel(
    selectInput(
      "playlist", "Select a Playlist Name", playlist_names)
  ),
  mainPanel(plotOutput("plot1"))
  
  
)

server <- function(input, output) {
  output$plot1<-renderPlot({playlist_name_plots(input$playlist)})
}


shinyApp(ui = ui, server = server)
schlumpel
  • 174
  • 1
  • 8