Reputation: 2079
I have a Shiny app which can either display a plot or print a dataframe. While it does both, it only prints the 1st 10 rows of the data frame and add "... 86 more rows". I would like to display at least 40 rows of the data frame. I tried both a & head(a, n=50) but it displays only 10 rows of the total. How can I make it display more rows.
This is what I have
output$IPLMatch2TeamsPlot <- renderPlot({
printOrPlotIPLMatch2Teams(input, output)
})
# Analyze and display IPL Match table
output$IPLMatch2TeamsPrint <- renderPrint({
a <- printOrPlotIPLMatch2Teams(input, output)
head(a,n=50)
#a
})
output$plotOrPrintIPLMatch2teams <- renderUI({
# Check if output is a dataframe. If so, print
if(is.data.frame(scorecard <- printOrPlotIPLMatch2Teams(input, output))){
verbatimTextOutput("IPLMatch2TeamsPrint")
}
else{ #Else plot
plotOutput("IPLMatch2TeamsPlot")
}
})
ui.R
tabPanel("Head to head",
headerPanel('Head-to-head between 2 IPL teams'),
sidebarPanel(
selectInput('matches2TeamFunc', 'Select function', IPLMatches2TeamsFuncs),
selectInput('match2', 'Select matches', IPLMatches2Teams,selectize=FALSE, size=20),
uiOutput("selectTeam2"),
radioButtons("plotOrTable1", label = h4("Plot or table"),
choices = c("Plot" = 1, "Table" = 2),
selected = 1,inline=T)
),
mainPanel(
uiOutput("plotOrPrintIPLMatch2teams")
)
Upvotes: 5
Views: 6692
Reputation: 1293
When you know your output is going to be a data.frame and not just any random bit of text, you can choose an output optimized for displaying tabular data. You could try renderTable
and tableOutput
instead of your renderPrint
and verbatimTextOutput
. Another option is renderDataTable
from the DT package. This create a table that puts extra rows on different pages so you can acces all rows and you can modify how many rows it will show at any time.
For example, replacing your current renderPrint
with the following:
output$IPLMatch2TeamsPrint <- DT::renderDataTable({
a <- printOrPlotIPLMatch2Teams(input, output)
datatable(a,
options = list(
"pageLength" = 40)
)
})
and replacing your verbatimTextOutput("IPLMatch2TeamsPrint")
with DT::dataTableOutput("IPLMatch2TeamsPrint")
Should give you a table with 40 rows and the option to see more rows as different pages in the table.
You might want to change the names from print to table as well for clarity since you're not just printing anymore.
Upvotes: 11