'Update dataframe based on shiny widgets' inputs
Im trying to create a dataframe which will update its values based on the shiny widgets selections in the sidebar. But the datatable I use to check this does not seem to display all column names and cell values .
library(shiny)
library(dplyr)
library(shinydashboard)
library(DT)
### user inter phase
ui <- fluidPage(
### App title ----
titlePanel(title=div(img(src="pics/IRP_NHSc.jpg", width="99%")))
,
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
### Input files ----
selectInput("Price","Select the price for analysis", c("List price","End consumer price without VAT", "End consumer price with VAT", "Reimbursed price"),multiple = T),
selectInput("IRP_A","Select IRP formula", c("Price average"="PA","Median price"="MP","3 lowest price average"="3L", "Lowest price"="LP", "Turkish rule"="TR", "Swiss rule"="SR" )),
# Input: Slider for the number of bins ----
sliderInput(inputId = "increase",
label = "% increase",
min = -20,
max = 100,
value = 35), width = 2,
),
### Main panel for displaying outputs ----
mainPanel(
tabsetPanel(
tabPanel("Export report",
dataTableOutput("tab7"))
)
)
)
)
#### Server
server <- function(input, output, session) {
output$tab7<-renderDataTable({
Price<-input$Price
IRP<-input$IRP_A
Per<-input$increase
df<-as.data.frame(Price,IRP,Per)
})
}
shinyApp(ui = ui, server = server)
Solution 1:[1]
I'm not really sure what you want to see but I think as.data.frame is taking only the first object as the thing to convert into a data frame and the second as the row name. If you put them in a list you can see all the inputs in the table:
df<-as.data.frame(list('price' = Price, 'irp' = IRP,'per' = Per))
(although it does give an error until you select at least one price)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Will |
