Shiny/R - Unable to rename column headers - r

Hoping for some expertise. the following code snippet does the following:
allows the user to select which variables (columns) they want from a CSV file, then generates numeric input fields for each one.
populates the dataframe with the values entered by the user.
However, Shiny assigns column headers to the data frame, and I've tried everything I could find to change them and nothing seems to work.
Can anyone tell me what I'm doing wrong?
df_sel() - this the function that selected the variables
this is the R.UI Section
ui <- fluidPage(
# App title ----
titlePanel(title = h1("Variable Selection Example", align = "center")),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Select a file ----
fileInput("uploaded_file", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
# Horizontal line ---- This allows the user to create a bunch of repeated values for the numerica inputs they later create
sliderInput("months", "Forecast Months:",
min = 0, max = 60,
value = 1),
tags$hr(),
# Input: Checkbox if file has header ----
checkboxInput("header", "Header", TRUE),
# Input: Select separator ----
radioButtons("sep", "Separator",
choices = c(Semicolon = ";",
Comma = ",",
Tab = "\t"),
selected = ","),
# Horizontal line ----
tags$hr(),
# Input: Select number of rows to display ----
radioButtons("disp", "Display",
choices = c(All = "all",
Head = "head"),
selected = "all"),
# Select variables to display ----
uiOutput("checkbox")
),
# Main panel for displaying outputs ----
mainPanel(
uiOutput("input_ui"), #numeric inputs
tableOutput("table1")) #table to display input values
)
)
this is in the R.Server section
server <- function(input, output, session) {
#assign csv file to dataframe df
df <- reactive({
req(input$uploaded_file)
read.csv(input$uploaded_file$datapath,
header = input$header,
sep = input$sep)
})
# Dynamically generate UI input when data is uploaded ----
output$checkbox <- renderUI({
checkboxGroupInput(inputId = "select_var",
label = "Select variables",
choices = setdiff(names(df()), input$select_dev),
selected = setdiff(names(df()), input$select_dev))
})
# Select columns to print ----
df_sel <- reactive({
req(input$select_var)
df_sel <- df() %>% select(input$select_var)
})
output$input_ui <- renderUI({ #this creates dynamic numeric inputs based on the variables selected by the user
pvars <- df_sel()
varn = names(df_sel())
lapply(seq(pvars), function(i) {
numericInput(inputId = paste0("range", pvars[i]),
label = varn,
value = 0)
})
})
numbers <- reactive({ #this creates a reactive dataframe for the numbers
pvars <- df_sel()
num = as.integer(ncol(pvars))
print(num)
pred <- data.frame(lapply(1:num, function(i) {
input[[paste0("range", pvars[i])]]
}))
n = input$months #pull number from that slider up in the UI section
pd = data.frame(pred, i=rep(1:n,ea=NROW(input$months)))
pd[1:(length(pd)-1)]
#colnames(pd, c(df_sel())) #this does not seem to work at all!!!
})
output$table1 <- renderTable({
numbers()
fv = numbers()
print(dim(fv)) #check the dimensions of the table
print(fv) # chcek the table is populating correctly.
#df1 <- fv #show the table
})
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)

I came up with a solution to my own question. If anyone can improve upon it, please let me know. This code goes in the R.Server section.
#This creates sliders from the selected variables from the reactive function called
#"df_sel()". Note the use of "tagList". The RenderUI function below creates as
#many sliders as variables selected, and passes in the correct variable name.
#It selects the last data value from each column, since this is time series data,
#the last data value \ (most recent) was desired.
output$scplan <- renderUI({
vars <- df_sel()
n = nrow(vars)
tagList(lapply(colnames(vars), function(z) {
sliderInput(
sprintf("%s",z),
label = z,
min = ceiling(min(vars[[z]])), # min value is the minimum of the column
max = ceiling(max(vars[[z]])), # max is the max of the column
value = vars[[z]][[n]])
}))
#this reactive function creates a dataframe from variables that were selected from
#checkboxes. The user moves the sliders to generate the values, and the code
#repeats the values for as many "input$months" as were selected.
sp_numbers <- reactive({
vars <- df_sel()
num = as.integer(ncol(vars))
sp_pred <- data.frame(lapply(colnames(vars), function(z) {
input[[z]]
}))
names(sp_pred) <- colnames(vars)
n = input$sp_months
df_sp_pred = data.frame(sp_pred, z=rep(z:n,ea=NROW(input$sp_months)))
df_sp_pred[1:(length(df_sp_pred)-1)] #this removes the last column which just shows the repeat count
})
#this code renders the table of the dataframe created above.
output$spo_table <- renderTable({
sp_numbers()
})

Related

Reactive sliderInput and dateRangeInput

I'm trying to make a reactive table using shiny and am having trouble making my sliderInput and dateRangeInput filters reactive and am not sure where to go from here. I'm using a data frame named "joined" to make an interactive table with. I've already been able to make my columns reactive luckily meaning I can choose which columns from the data frame joined are present in the table, so any of the code about selecting certain columns can be ignored.
My goal for the dateRangeInput is that a date range can be put into the dateRangeInput and only dates that fall into that range in the "actiondate" column on my table "joined" will be displayed in the resulting table.
My goal for the sliderInput is that I can choose a range in the slider and only values of "EPM_scores" column in my table "joined" will be displayed in the resulting table.
Below is my code. Any advice I could get would be much appreciated. Thanks!
The current error message I'm getting is as follows: "error in evaluating the argument 'condition' in selecting a method for function 'filter': unused argument (input$dates[2])"
titlePanel("title"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "Value", "1. Enter value", min = 0, max = 1, c(0,1), step = 0.01),
dateRangeInput(inputId = "dates",
"2. Enter date range",
start = min(joined$actiondate),
end = max(joined$actiondate)),
uiOutput("picker"),
actionButton("view", "View selection"),
textOutput("DateRange")),
mainPanel(ui <-
tableOutput("mytable"),
textOutput("mytext")
)),
textInput(inputId = "text",
label = "4. Enter Notes Here", "")
)
server <- function(input, output, session) {
#columns selected
data <- reactive({
joined
})
output$picker <- renderUI({
pickerInput(inputId = 'pick',
label = '3. Choose variables',
choices = colnames(data()),
options = list(`actions-box` = TRUE), multiple = TRUE)
})
datasetInput <- eventReactive(input$view,{
datasetInput <- data() %>%
dplyr::select(input$pick)
return(datasetInput)
})
#dates selected
newDates <- reactive({
filter(joined, between(actiondate, input$dates[1], input$dates[2]))
})
#slider values selected
sliderValues <- reactive({
Value = c(input$value[1], input$value[2])
})
output$mytext <- renderText(input$text)
output$mytable <- renderTable({
datasetInput()
newDates()
sliderValues()
})
}

Shiny: How to merge and abbreviate inputs to extract data from excel sheet?

I am trying to set up an entry mask for users to enter distinct inputs in two fields that in turn extract data from an external excel sheet. The two input fields are Geography and World Region. There are several options to pick from for both fields, i.e. Africa or United States for Geography. The user can add as many input rows as he would like. The excel sheet that runs in the background has multiple columns, one for each possible combination of inputs that the user can select. Each column is named as a combined character string of the two abbreviations of the possible input options and has data in it that should be extracted and used later on.
Once the user has submitted their data, the string of characters made up of the two abbreviations should be produced for each input row so that it can be used to extract the data out of the respective column in the excel sheet. E.g if in the first input row the user has selected "Africa" and "Region1" the data of the column "Afr_Em" should be used. This should happen for each row of input the user indicates.
Right now, I am trying to store the abbreviations of the two fields in InputList to use this later to extract the data but it does not seem to work.
Here is my code so far:
# library(packages,etc.)
GeographyList <- c("Africa"="Afr",
"Asia"="AS",
"Europe"="EU")
WorldRegionList <- c("Region1"="Em",
"Region2"="Dev")
ui <- fluidPage(#....design etc.,
# this is just a demo to show the input values
mainPanel(
uiOutput("inputwidgets"),
actionButton('number',
'Add row'),
actionButton('delete_number',
'Delete row'),
actionButton("update", "Update View"),
h4("allocation"),
plotOutput("allocation"),
textOutput("labels"))
)
server <- function(input, output) {
# (For remove button) Reactive value that is triggered by add and remove button
reac <- reactiveValues()
observeEvent(c(input$number,input$delete_number), {
# you need to add 1 to not start with 0
add <- input$number+1
# restriction for delete_number > number
delete <- if(input$delete_number > input$number) add else input$delete_number
calc <- add - delete
reac$calc <- if(calc > 0) 1:calc else 1
})
# Get new input by clicking Add Row
observe({
req(reac$calc)
output$inputwidgets = renderUI({
input_list <- lapply(reac$calc, function(i) {
Geography <- input[[paste0("Geography",i)]]
Region <- input[[paste0("WorldRegion",i)]]
amount <- input[[paste0("amount",i)]]
fluidRow(
column(2,
selectInput(paste0("Geography", i),
label = paste0("Geography", i),
choices = GeographyList,
multiple = FALSE,
selected = if(!is.null(Geography)) Geography)
),
column(3,
selectInput(paste0("WorldRegion", i),
label = paste0("World Region", i),
choices = WorldRegionList,
multiple = FALSE,
selected = if(!is.null(Region)) Region)),
column(3,
# Input: Specify the amount ----
numericInput(
paste0("amount",i),
label="Amount",
value = if(!is.null(amount)) amount else 0
)
)
)
})
do.call(tagList, input_list)
})
})
# List with the desired abbreviations, 1 abbreviation for each row
InputList <- eventReactive(input$update,{
lapply(1:input$number, function(i) {
paste0(eval(parse(text=paste0("input$Geography",i))),"_",eval(parse(text=paste0("input$WorldRegion",i))))
})})
output$labels <- renderText({ paste0(InputList()) })
# List with the desired abbreviations, 1 abbreviation for each row
allocation <- eventReactive(input$update, {
x <- c(input$amount1, input$amount2, input$amount3)
lbls <- c(paste0(InputList()))
pie(x, labels = lbls)
})
output$allocation <- renderPlot({
if (input$update == 0)
return()
(allocation())
})
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
and this is basically how the excel sheet looks like (at least partly, adding all possible combinations of abbreviations would be too much but I hope you understand the structure):
Afr_EM Afr_EM Afr_EM ... LAC_Dev
5 5 3 ... 7
3 1 2 ... 8
...
As I am very new to shiny, I would appreciate any kind of help!
Please test the below:
GeographyList <-list("Africa"="Afr",
"Asia"="AS",
"Europe"="EU")
WorldRegionList <- list("Region1"="Em",
"Region2"="Dev")
ui <- fluidPage(#....design etc.,
# this is just a demo to show the input values
mainPanel(
uiOutput("inputwidgets"),
actionButton('number',
'Add row'),
# Input: Click to run input
actionButton("update", "Run")))
server <- function(input, output) {
# By clicking the actionButton an additional row appears
observeEvent(input$number, {
output$inputwidgets = renderUI({
input_list <- lapply(1:input$number, function(i) {
fluidRow(
column(2,
selectInput(paste0("Geography", i),
label = paste0("Geography", i),
choices = GeographyList,
multiple = FALSE,
selected = NA)
),
column(3,
selectInput(paste0("WorldRegion", i),
label = paste0("World Region", i),
choices = WorldRegionList,
multiple = FALSE,
selected = NA)
))
})
do.call(tagList, input_list)
})
})
# List with the desired abbreviations, 1 abbreviation for each row
InputList <- eventReactive(input$update,{
lapply(1:input$number, function(i) {
paste0(eval(parse(text=paste0("input$Geography",i))),"_",eval(parse(text=paste0("input$WorldRegion",i))))
})})
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
I have created the 2 lists at the beginning as actual named lists. This removes the need for your switch see here by choices. I don't have the full code but it seems to be working from what I can see.
I have figured it out with the help of #Eli Berkow.
When including an action button to delete rows, I need to replace input$number in the InputList function with tail(reac$calc, n=1) to fetch the number of rows used.
Here is my full code:
# library(packages,etc.)
GeographyList <- c("Africa"="Afr",
"Asia"="AS",
"Europe"="EU")
WorldRegionList <- c("Region1"="Em",
"Region2"="Dev")
ui <- fluidPage(#....design etc.,
# this is just a demo to show the input values
mainPanel(
uiOutput("inputwidgets"),
actionButton('number',
'Add row'),
actionButton('delete_number',
'Delete row'),
actionButton("update", "Update View"),
h4("allocation"),
plotOutput("allocation"),
textOutput("labels"))
)
server <- function(input, output) {
# (For remove button) Reactive value that is triggered by add and remove button
reac <- reactiveValues()
observeEvent(c(input$number,input$delete_number), {
# you need to add 1 to not start with 0
add <- input$number+1
# restriction for delete_number > number
delete <- if(input$delete_number > input$number) add else input$delete_number
calc <- add - delete
reac$calc <- if(calc > 0) 1:calc else 1
})
# Get new input by clicking Add Row
observe({
req(reac$calc)
output$inputwidgets = renderUI({
input_list <- lapply(reac$calc, function(i) {
Geography <- input[[paste0("Geography",i)]]
Region <- input[[paste0("WorldRegion",i)]]
amount <- input[[paste0("amount",i)]]
fluidRow(
column(2,
selectInput(paste0("Geography", i),
label = paste0("Geography", i),
choices = GeographyList,
multiple = FALSE,
selected = if(!is.null(Geography)) Geography)
),
column(3,
selectInput(paste0("WorldRegion", i),
label = paste0("World Region", i),
choices = WorldRegionList,
multiple = FALSE,
selected = if(!is.null(Region)) Region)),
column(3,
# Input: Specify the amount ----
numericInput(
paste0("amount",i),
label="Amount",
value = if(!is.null(amount)) amount else 0
)
)
)
})
do.call(tagList, input_list)
})
})
# List with the desired abbreviations, 1 abbreviation for each row
InputList <- eventReactive(input$update,{
lapply(1:tail(reac$calc, n=1), function(i) {
paste0(eval(parse(text=paste0("input$Geography",i))),"_",eval(parse(text=paste0("input$WorldRegion",i))))
})})
output$labels <- renderText({ paste0(InputList()) })
# List with the desired abbreviations, 1 abbreviation for each row
allocation <- eventReactive(input$update, {
x <- c(input$amount1, input$amount2, input$amount3)
lbls <- c(paste0(InputList()))
pie(x, labels = lbls)
})
output$allocation <- renderPlot({
if (input$update == 0)
return()
(allocation())
})
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)

Select and scale variables in shiny app dynamically

I have a shiny app where I want the user to be able to select which variables to keep in the final data frame and then also select which variables to scale into a percent. I have this working, but I am running into a little puzzle. The problem is if the user decides they want to add an additional variable (or remove one), they have to redo the scaling. This could be a problem if my users have many columns they are working on. How can I keep the scaling work the user has already done, while allowing for the addition or removal of variables from the final data frame?
library(shiny)
library(tidyverse)
library(DT)
# Define UI
ui <- fluidPage(
checkboxGroupInput("select_var", label = "Select Variables"),
selectInput("scalescore", label = NULL, choices = c("")),
actionButton("scale", "Scale Scores"),
DT::dataTableOutput("table")
)
# Define server
server <- function(session, input, output) {
# define the reactive values
values <- reactiveValues(df_final = NULL)
# dynamically generate the variable names
observe({
vchoices <- names(mtcars)
updateCheckboxGroupInput(session, "select_var", choices = vchoices)
})
# dynamically generate the variables to scale
observe({
vchoices <- names(values$df_final)
updateSelectInput(session, "scalescore", choices = vchoices)
})
# select the variables based on checkbox
observe({
req(input$select_var)
df_sel <- mtcars %>% select(input$select_var)
values$df_final <- df_sel
})
observeEvent(input$scale, {
name <- rlang::sym(paste0(input$scalescore, "_scaled"))
values$df_final <- values$df_final %>% mutate(!!name := round(!!rlang::sym(input$scalescore)/max(!!rlang::sym(input$scalescore), na.rm = TRUE)*100, 1))})
output$table <- DT::renderDataTable(values$df_final)
}
# Run the application
shinyApp(ui = ui, server = server)
We will need to maintain a vector which tracks whether a variable was scaled or not. Here is how it's done,
library(shiny)
library(tidyverse)
library(DT)
# Define UI
ui <- fluidPage(
checkboxGroupInput("select_var", label = "Select Variables"),
selectInput("scalescore", label = NULL, choices = c("")),
actionButton("scale", "Scale Scores"),
DT::dataTableOutput("table")
)
server = function(input,output,session){
#Column names are static
names = colnames(mtcars)
# data scructure to store if the variable is scaled
is_scaled = logical(length(names))
names(is_scaled) = names #Set the names of the logical vector to the column names
#Update the checkbox with the column names of the dataframe
observe({
updateCheckboxGroupInput(session, "select_var", choices = names)
})
# Update the list of choices but dont include the scaled vaiables
observe({
vchoices <- names(data())
vchoices = vchoices[vchoices %in% names]
updateSelectInput(session, "scalescore", choices = vchoices)
})
#When the scle button is pressed, the vector which contains the list of scaled variables is updated
observeEvent(input$scale,{
if(is_scaled[[input$scalescore]]){
is_scaled[[input$scalescore]] <<- FALSE
}else{
is_scaled[[input$scalescore]] <<- TRUE
}
})
#Function to scale the variables
scale = function(x){
return(round(x/max(x,na.rm = T)*100,1))
}
data = reactive({
req(input$select_var)
input$scale #simply to induce reactivity
#Select the respective columns
df = mtcars%>%
select(input$select_var)
if(any(is_scaled[input$select_var])){
temp_vec = is_scaled[input$select_var] #Get a list of variables selected
true_vec = temp_vec[which(temp_vec)] #Check which ones are scaled
true_vec_names = names(true_vec) #Get the names of the variables scales
#Scale the variables respectively
df = df%>%
mutate_at(.vars = true_vec_names,.funs = funs(scaled = scale(.)))
}
return(df)
})
output$table = DT::renderDataTable(data())
}
# Run the application
shinyApp(ui = ui, server = server)
is_scaled tracks whether a particular column is scaled or not. When it is later selected, it is scaled if the value is TRUE in this vector.
Additional functionality is also added where if the scale button is pressed twice the scale column is removed.

R/Shiny Dataframe Columns

I'm working with Shiny, and i have another question, hopefully much easier:
I have a dataframe (uploaded from a CSV), where I want the user to select a Dependent variable, and then select their independent variables, but the list of available columns for the IV selection should now not include the dependent variable that they just selected.
I've been staring and reactive expressions all day, and have no clue. It's probably really obvious too.
Any help would be great.
Here is a code snippet from the Server code
# Read file ----
df <- reactive({
req(input$uploaded_file)
read.csv(input$uploaded_file$datapath,
header = input$header,
sep = input$sep)
})
# dynamically allow the user to select a dependent variable ----
output$selectbox <- renderUI({
selectInput(inputId = "select_dev",
label = "Select target variable",
choices = names(df()))
})
# Dynamically allow the user to select their independent variables using checkboxes ----
###
### Here is where I would like to remove the variable from the DF that they selected in output$selectbox.
###
output$checkbox <- renderUI({
checkboxGroupInput(inputId = "select_var",
label = "Select variables",
choices = names(df()),
selected = names(df()))
})
Perhaps there is an easier way than this to manipulate a reactive function. The goal is to have dataframe that I can treat as a set of independent variables, and be able to call on it for multiple analyses.
There you go -
library(shiny)
shinyApp(
ui = fluidPage(
uiOutput("selectbox"),
uiOutput("checkbox")
),
server = function(input, output, session) {
df <- reactive(iris)
output$selectbox <- renderUI({
selectInput(inputId = "select_dev",
label = "Select target variable",
choices = names(df()))
})
output$checkbox <- renderUI({
checkboxGroupInput(inputId = "select_var",
label = "Select variables",
choices = setdiff(names(df()), input$select_dev),
selected = setdiff(names(df()), input$select_dev))
})
}
)

Two Reactives R Shiny

I need to render a table based on user input which will be one of two possible tables. I have defined the first table filedata by the user selecting a .csv file to upload. The second table, data_ranked_words, has the same dimensions.
What I want is for the output to switch between the two tables. I defined each table in a reactive(). However, I know that the data_ranked_words reactive is never being triggered. How do I trigger both of these reactives when the user uploads a file? In my code the issue is with the two reactive() statements at the beginning of server.R.
library(shiny)
library(markdown)
library(DT)
library(D3TableFilter)
options(shiny.maxRequestSize=50*1024^2)
setwd('~/Desktop/DSI/Topic Model App Interface')
# ui.R
#-------------------------------------------------------------------------------------
ui <- shinyUI(
navbarPage("Start",
tabPanel("From Data",
sidebarLayout(
sidebarPanel(
radioButtons("plotType", "Plot type",
c("Scatter"="p", "Line"="l")
)
),
mainPanel(
plotOutput("plot")
)
)
),
tabPanel("From CSV",
sidebarLayout(
sidebarPanel(
# Define what's in the sidebar
fileInput("file",
"Choose CSV files from directory",
multiple = TRUE,
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
h5(div(HTML('Use the radio butons to toggle between the <em>Word View</em> and
<em>Probability View</em>.'))),
radioButtons('toggle', 'Choose one:', list('Word View', 'Probability View')),
p(div(HTML('<strong>Note:</strong> The <em>Probability View</em> will
<u>not</u> yield the top X number of words. It will instead
return the first X columns. You can then sort each column in
ascending or descending order. Keep in mind that it will only
sort from the rows that are displayed, <u>not</u> all rows.'))),
br(),
sliderInput('slider', div(HTML('How many rows to display?')), 1, 100, 20),
br(),
h5('Use the buttons below to quickly show large numbers of rows.'),
radioButtons('rowIdentifier', 'Show more rows:',
list('[ Clear ]', '200', '500', '1000', '5000', '10000', 'All Rows')),
p(div(HTML('<strong>Warning:</strong> Printing all rows to the screen may
take a while.'))),
h3('Tips:'),
p("You can copy and paste the table into Excel. If you only want to
copy one column, use the 'Show/Hide' function at the top-right of the table
to hide all the undesired columns."),
p(div(HTML('Sorting by column is available in <em>Probability View</em> but
not <em>Word View</em>.')))
),
# Define what's in the main panel
mainPanel(
title = 'Topic Model Viewer',
# How wide the main table will be
fluidRow(
column(width = 12, d3tfOutput('data'))
)
)
)
),
navbarMenu("More",
tabPanel("temp"
),
tabPanel("About",
fluidRow(
column(6
),
column(3
)
)
)
)
)
)
# server.R
#-------------------------------------------------------------------------------------
server <- shinyServer(function(input, output, session) {
# Set up the dataframe for display in the table
# Define 'filedata' as the .csv file that is uploaded
filedata <- reactive({
infile <- input$file
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
temp = read.csv(infile$datapath)
# Save data as RDS file, which is much faster than csv
saveRDS(temp, file = 'data.rds')
# Read in data file
data = readRDS('data.rds')
# Transpose data for more intuitive viewing. Words as rows, topics as cols
data = t(data)
# Convert to data frame
data = as.data.frame(data)
# Return this
data
})
# The ranked and ordered csv file
data_ranked_words <- reactive({
data = filedata()
# Sort each column by probability, and substitute the correct word into that column
# This will essentially rank each word for each topic
# This is done by indexing the row names by the order of each column
temp = matrix(row.names(data)[apply(-data, 2, order)], nrow(data))
temp = as.data.frame(temp)
# Define column names (same as before) for the new data frame
colnames(temp) = paste0(rep('topic', ncol(data)), 1:ncol(data))
# Return this
temp
print('Success')
})
output$data <- renderD3tf({
# Define table properties. See http://tablefilter.free.fr/doc.php
# for a complete reference
tableProps <- list(
rows_counter = TRUE,
rows_counter_text = "Rows: ",
alternate_rows = TRUE
);
# Radio buttons
# The reason why the extensions are in this if() is so that sorting can be
# activated on Probability View, but not Word View
if(input$toggle=='Word View'){
df = data_ranked_words
extensions <- list(
list( name = "colsVisibility",
text = 'Hide columns: ',
enable_tick_all = TRUE
),
list( name = "filtersVisibility",
visible_at_start = FALSE)
)
} else if(input$toggle=='Probability View'){
df = filedata()
extensions <- list(
list(name = "sort"), #this enables/disables sorting
list( name = "colsVisibility",
text = 'Hide columns: ',
enable_tick_all = TRUE
),
list( name = "filtersVisibility",
visible_at_start = FALSE)
)
}
# Radio button options for more row viewing options
if(input$rowIdentifier=='Clear'){
num_rows = input$slider
} else if(input$rowIdentifier==200){
num_rows = 200
} else if(input$rowIdentifier==500){
num_rows = 500
} else if(input$rowIdentifier==1000){
num_rows = 1000
} else if(input$rowIdentifier==5000){
num_rows = 5000
} else if(input$rowIdentifier==10000){
num_rows = 10000
} else if(input$rowIdentifier=='All Rows'){
num_rows = nrow(df)
} else{
num_rows = input$slider
}
# Create table
if(is.null(filedata())){
} else{
d3tf(df,
tableProps = tableProps,
extensions = extensions,
showRowNames = TRUE,
tableStyle = "table table-bordered")
}
})
# This line will end the R session when the Shiny app is closed
session$onSessionEnded(stopApp)
})
# Run app in browser
runApp(list(ui=ui,server=server), launch.browser = TRUE)

Resources