Tkinter Treeview grid alignment issue - python-2.7
How can I make the treeview widget stick to the Noth (to the toolbar) when scaling up the application window.
It sticks to the west South and Est, but not the North.
using :
self.tree.grid(row=1,column=0,sticky=N+W+E+S)
I
This is the tree.grid alignment configuration
...
self.vsb = ttk.Scrollbar(master, orient=VERTICAL, command=self.tree.yview)
self.hsb = ttk.Scrollbar(master, orient=HORIZONTAL, command=self.tree.xview)
self.vsb.grid(row=1, column=1, sticky='ns')
self.hsb.grid(row=2, column=0, sticky='ew')
self.tree.configure(yscrollcommand=self.vsb.set)
self.tree.configure(xscrollcommand=self.hsb.set)
self.tree.grid(row=1,column=0,sticky=N+W+E+S)
...
This is the toolbar grid config (in case it causes the issue)
...
self.toolbar = Frame(master, bg="blue")
self.upButton = Button(self.toolbar, text="Up", command=self.doNothing, padx=10, pady=10)
self.upButton.grid(row=0,column=0,sticky=N+W)
self.downButton = Button(self.toolbar, text="Down", command=self.doNothing, padx=10, pady=10)
self.downButton.grid(row=0,column=1, sticky=N+W)
self.insupButton = Button(self.toolbar, text="Insert UP", command=lambda: self.insertUp(self.tree), padx=10, pady=10)
self.insupButton.grid(row=0,column=2, sticky=N+W)
self.insdownButton = Button(self.toolbar, text="Insert Down", command=lambda: self.insertDown(self.tree), padx=10, pady=10)
self.insdownButton.grid(row=0,column=3, sticky=N+W)
self.delbrButton = Button(self.toolbar, text="Delete branch", command=lambda: self.deleteBr(self.tree), padx=10, pady=10)
self.delbrButton.grid(row=0,column=4, sticky=N+W)
self.deltreeButton = Button(self.toolbar, text="Delete entire tree", command=lambda: self.deleteTr(self.tree), padx=10, pady=10)
self.deltreeButton.grid(row=0,column=5, sticky=N+W)
self.searchButton = Button(self.toolbar, text='Search', command=lambda: self.searchTr(self.tree), padx=10, pady=10)
self.searchButton.grid(row=0,column=6, sticky=N+W)
self.calcButton = Button(self.toolbar, text='Calc', command=lambda: self.calcTree(self.tree), padx=10, pady=10)
self.calcButton.grid(row=0,column=7, sticky=N+W)
self.toolbar.grid(row=0,column=0, sticky=N+W)
...
Application at launch:
Observed result: Application scaled up
Observed result: Application scaled down (overlaps with the toolbar)
Desired result: Application scaled up
Your tree is sticking to the north, it's just that the top of the row is further down than you realize. You need to give one or more rows a weight, so that tkinter will allocate extra space to that row (and not to any rows with the default weight of zero).
For example:
master.grid_rowconfigure(1, weight=1)
For a definitive reference to how the grid algorithm works see http://tcl.tk/man/tcl8.5/TkCmd/grid.htm#M32
Related
argument "sidebar" is missing, with no default when creating shiny script
I'm creating a shiny app for an app that predicts morphine consumption based on several variables. When I attempt to run the app I receive a sidebar error message stating I am missing script to create the sidebar ("argument "sidebar" is missing, with no default"). Here is my ui and server script. #Load libraries library(shiny) library(shinydashboard) library(ggplot2) library(dplyr) library(randomForest) library(Metrics) #R Shiny ui ui <- dashboardPage(dashboardHeader(title = 'Morphine Consumption Explorer', titleWidth = 290)) #Sidebar layout dashboardSidebar(sidebarMenu(id = "menu", sidebarMenuOutput("menu"))) sidebarMenu(menuItem("Plots", tabName = "plots", icon = icon('poll')), menuItem("Dashboard", tabName = "dash", icon = icon('tachometer-alt')), menuItem("Prediction", tabName = "pred", icon = icon('search'))) #pick variables #Tabs layout dashboardBody(tags$head(tags$style(HTML('.main-header .logo {font-weight: bold;}')))) tabItems() #Plots tab content tabItem('plots', #Histogram filter box(status = 'primary', title = 'Filter for the histogram plot', selectInput('num', "Numerical variables:", c("Age", "BMI", "IV_Fluids", "Operative_times", "Blood_loss", "Time_to_Aldrete_9", "morphine_consumption_24h1", "VAS_basalR", "VAS_basalM", "VAS_2hrR", "VAS_2hrM", "VAS_4hrM", "VAS-4hrR", "VAS_8hrR", "VAS_8hrM", "VAS_12hrR", "VAS_12hrM", "VAS_16hrR", "VAS_16hrM", "VAS_24hrR", "VAS_24hrM", "QOR_psychological_support", "QOR_emotional_state", "QOR_Physical_comfort", "QOR_physical_independence", "QOR_Pain", "Total")), footer = 'Histogram plot for numerical variables'), #Frequency plot filter box(status = 'primary', title = 'Filter for the frequency plot', selectInput('cat', 'Categorical variables:', c("ASA", "Postoperative_vomiting", "Sedation_0to8h", "Sedation_9to16h", "Sedation_17to24h")), footer = 'Frequency plot for categorical variables'), #Boxes to display the plots box(plotOutput('histPlot')), box(plotOutput('freqPlot'))) #Prediction tab content tabItem('pred', #Filters for categorical variables box(title = 'Categorical variables', status = 'primary', width = 12, splitLayout( tags$head(tags$style(HTML(".shiny-split-layout > div {overflow: visible;}"))), cellWidths = c('0%', '19%', '4%', '19%', '4%', '19%', '4%', '19%', '4%', '8%'), selectInput( 'p_group', 'group', c("0", "30", "60", "90")), div(), selectInput('p_ASA', 'ASA', c('1', '2', '3')), div(), selectInput( 'p_Sedation_17to24h', 'Ramsey Sedation at 17-24h', c('1', '2', '3', '4')), div(), radioButtons( 'p_Postoperative_vomiting', 'PONV', c('Yes', 'No')))), #Filters for numeric variables box(title = 'Numerical variables', status = 'primary', width = 12, splitLayout(cellWidths = c('22%', '4%','21%', '4%', '21%', '4%', '21%'), sliderInput( 'p_Age', 'Age (year)', min = 0, max = 100, value = 0), div(), numericInput( 'p_BMI', 'BMI', 0), div(), numericInput( 'p_VAS_24hrM', 'VAS with Movement at 24hr', 0), div(), numericInput( 'p_QOR_psychological_support', 'QOR - Psychological Support', 0), div(), numericInput( 'p_QOR_Pain', 'QOR - Pain', 0), numericInput( 'p_QOR_Physical_comfort', 'QOR - Physical Comfort', 0), div(), )), #Box to display the prediction results box(title = 'Prediction result', status = 'success', solidHeader = TRUE, width = 4, height = 260, div(h5('Morphine Consumption (mg):')), verbatimTextOutput("value", placeholder = TRUE), div(h5('Range of Morphine Consumption:')), verbatimTextOutput("range", placeholder = TRUE), actionButton('cal','Calculate', icon = icon('calculator'))), #Box to display information about the model box(title = 'Model explanation', status = 'success', width = 8, height = 260, helpText('The following model will predict the total amount of morphine consumed by age, BMI, Visual Analog Scale at 24 hours with movement, and Quality of Recovery.'), helpText('The name of the dataset used to train the model is "Short-term efficacy of preoperative Duloxetine for patients subjected to modified radical mastectomy A dose ranging randomized controlled trial", taken from the UCI Machine Learning Repository website. The data contains 17,379 observations and 16 attributes related to time and weather conditions.'), helpText(sprintf('The prediction is based on a random forest supervised machine learning model. Furthermore, the models deliver a mean absolute error (MAE) of %s morphine consumed, and a root mean squared error (RMSE) of %s total number of morphine consumed.', round(mae_rf, digits = 0), round(rmse_rf, digits = 0))))) # R Shiny server server <- shinyServer(function(input, output) { #Univariate analysis output$histPlot <- renderPlot({...}) output$freqPlot <- renderPlot({...}) #Dashboard analysis output$linePlot <- renderPlot({...}) output$barPlot <- renderPlot({...}) #Prediction model #React value when using the action button a <- reactiveValues(result = NULL) observeEvent(input$cal, { #Copy of the test data without the dependent variable test_pred <- test_set[-10] #Dataframe for the single prediction values = data.frame(mnth = input$p_mnth, Group = input$p_group, ASA = input$p_ASA, Sedation_17to24hr = input$p_Sedation_17to24h, PONV = input$p_Postoperative_vomiting) #Include the values into the new data test_pred <- rbind(test_pred,values) #Single preiction using the randomforest model a$result <- round(predict(model_rf, newdata = test_pred[nrow(test_pred),]), digits = 0) }) output$value <- renderText({ #Display the prediction value paste(a$result) }) output$range <- renderText({ #Display the range of prediction value using the MAE value input$cal isolate(sprintf('(%s) - (%s)', round(a$result - mae_rf, digits = 0), round(a$result + mae_rf, digits = 0))) }) }) shinyApp(ui, server) I appreciate any feedback. Thank you. A I tried manipulating the sidebar script after I ran the app. I'm expecting a shiny app that allows me to picture variables and estimate morphine consumption.
The header, sidebar and body functions need to passed as parameters to the dashboardPage(header, sidebar, body, title = NULL) function. Please check the following: # Load libraries library(shiny) library(shinydashboard) library(shinydashboardPlus) library(ggplot2) library(dplyr) library(randomForest) library(Metrics) # R Shiny ui ui <- dashboardPage(header = dashboardHeader(title = 'Morphine Consumption Explorer', titleWidth = 290), sidebar = dashboardSidebar(sidebarMenu(menuItem("Plots", tabName = "plots", icon = icon('poll')), menuItem("Dashboard", tabName = "dash", icon = icon('tachometer-alt')), menuItem("Prediction", tabName = "pred", icon = icon('search')), id = "menu")), body = dashboardBody(tags$head(tags$style(HTML('.main-header .logo {font-weight: bold;}'))), tabItems( #Plots tab content tabItem('plots', #Histogram filter box(status = 'primary', title = 'Filter for the histogram plot', selectInput('num', "Numerical variables:", c("Age", "BMI", "IV_Fluids", "Operative_times", "Blood_loss", "Time_to_Aldrete_9", "morphine_consumption_24h1", "VAS_basalR", "VAS_basalM", "VAS_2hrR", "VAS_2hrM", "VAS_4hrM", "VAS-4hrR", "VAS_8hrR", "VAS_8hrM", "VAS_12hrR", "VAS_12hrM", "VAS_16hrR", "VAS_16hrM", "VAS_24hrR", "VAS_24hrM", "QOR_psychological_support", "QOR_emotional_state", "QOR_Physical_comfort", "QOR_physical_independence", "QOR_Pain", "Total")), footer = 'Histogram plot for numerical variables'), #Frequency plot filter box(status = 'primary', title = 'Filter for the frequency plot', selectInput('cat', 'Categorical variables:', c("ASA", "Postoperative_vomiting", "Sedation_0to8h", "Sedation_9to16h", "Sedation_17to24h")), footer = 'Frequency plot for categorical variables'), #Boxes to display the plots box(plotOutput('histPlot')), box(plotOutput('freqPlot'))), #Prediction tab content tabItem('pred', #Filters for categorical variables box(title = 'Categorical variables', status = 'primary', width = 12, splitLayout( tags$head(tags$style(HTML(".shiny-split-layout > div {overflow: visible;}"))), cellWidths = c('0%', '19%', '4%', '19%', '4%', '19%', '4%', '19%', '4%', '8%'), selectInput( 'p_group', 'group', c("0", "30", "60", "90")), div(), selectInput('p_ASA', 'ASA', c('1', '2', '3')), div(), selectInput( 'p_Sedation_17to24h', 'Ramsey Sedation at 17-24h', c('1', '2', '3', '4')), div(), radioButtons( 'p_Postoperative_vomiting', 'PONV', c('Yes', 'No')))), #Filters for numeric variables box(title = 'Numerical variables', status = 'primary', width = 12, splitLayout(cellWidths = c('22%', '4%','21%', '4%', '21%', '4%', '21%'), sliderInput( 'p_Age', 'Age (year)', min = 0, max = 100, value = 0), div(), numericInput( 'p_BMI', 'BMI', 0), div(), numericInput( 'p_VAS_24hrM', 'VAS with Movement at 24hr', 0), div(), numericInput( 'p_QOR_psychological_support', 'QOR - Psychological Support', 0), div(), numericInput( 'p_QOR_Pain', 'QOR - Pain', 0), numericInput( 'p_QOR_Physical_comfort', 'QOR - Physical Comfort', 0), div(), )), #Box to display the prediction results box(title = 'Prediction result', status = 'success', solidHeader = TRUE, width = 4, height = 260, div(h5('Morphine Consumption (mg):')), verbatimTextOutput("value", placeholder = TRUE), div(h5('Range of Morphine Consumption:')), verbatimTextOutput("range", placeholder = TRUE), actionButton('cal','Calculate', icon = icon('calculator'))), #Box to display information about the model box(title = 'Model explanation', status = 'success', width = 8, height = 260, helpText('The following model will predict the total amount of morphine consumed by age, BMI, Visual Analog Scale at 24 hours with movement, and Quality of Recovery.'), helpText('The name of the dataset used to train the model is "Short-term efficacy of preoperative Duloxetine for patients subjected to modified radical mastectomy A dose ranging randomized controlled trial", taken from the UCI Machine Learning Repository website. The data contains 17,379 observations and 16 attributes related to time and weather conditions.'), helpText(sprintf('The prediction is based on a random forest supervised machine learning model. Furthermore, the models deliver a mean absolute error (MAE) of %s morphine consumed, and a root mean squared error (RMSE) of %s total number of morphine consumed.', round(mae_rf, digits = 0), round(rmse_rf, digits = 0))) )) ) ), title = 'Morphine Consumption Explorer', skin = "blue") server <- function(input, output, session) {} shinyApp(ui, server)
Is there a way to freeze the horizontal scroller in DT?
I have a data frame with a lot of rows and columns, so I added a horizontal scroll bar so the columns wouldn't be squished. However In order to access the scroll bar I need to scroll all the way to the bottom of the datatable. Is there an option to lock the horizontal scroll bar to the bottom of your screen and not the bottom of the datatable in the base DT package or do I need a DT extension? output$sheet <- renderDT({ datatable( display_table(), options = list( scrollX = TRUE, autoWidth = TRUE, pageLength = nrow(display_table()), columnDefs = list( list(width = "65px", targets = c(1,11)), list(className = 'dt-center', targets = "_all") ) ) ) })
replacing a new interface with old one in tkinter
I've created a class that has a function called mainScreen(). It simply prints the main screen with two buttons on it. If you press any button, it must go to another function called signup(). I want to clear the whole frame and create new widgets but I can't clear the widgets class graphics: def __init__(self, master): self.root = master def mainscreen(self): helv36 = tkFont.Font(family='Century Gothic', size=20) mainFrame = Frame(self.root) mainFrame.config(relief='sunken', width=1280, height=720, bg='light blue') mainFrame.pack(expand='yes', fill='both') inButton = Button(mainFrame, text = "Sign up", bd = 10, relief = GROOVE, font = helv36) inButton.bind("<Button-1>", self.signup) inButton.place(bordermode = OUTSIDE, width =160, height = 60, x = 600, y = 300) upButton = Button(mainFrame, text = "Sign in", bd = 10, relief = GROOVE, font = helv36) upButton.bind("<Button-1>", self.signup) upButton.place(bordermode = OUTSIDE, width =160, height = 60, x = 600, y = 400) mainFrame.pack_propagate(FALSE) self.root.mainloop() def signup(self,event): signUpShow = Frame(self.root) signUpShow.config(relief='sunken', width=1280, height=720, bg='light yellow') signUpShow.pack(expand='yes', fill='both')
You __init__ needs to have its code indented and it needs a call to mainscreen. The solution to mainFrame being local within mainscreen is to make it also an attribute. self.mainframe = mainFrame = Frame(self.root) Then you can access self.mainframe within signup.
Trying to subset in the Plotly call using Shiny input still plots on full data frame
The following code works to an extent - it plots a graph, but it is very clearly not subsetting the original data frame, but plotting based on all the indicators, years etc. Any thoughts on why? I have tried wrapping in reactive, using select(filter from dplyr, using "" around the input$indicator etc. I have spent about 4 hours looking through various suggestions on here, Plotly and Shiny sites, without a solution. Starting to doubt I'll ever get the hang of this. # # This is a Shiny web application. You can run the application by clicking # the 'Run App' button above. # library(dplyr) library(shiny) library(fingertipsR) library(viridis) library(plotly) #Import QOF indicators setwd("/Users/ianbowns/Documents/R/ShinyFT") dat <- readRDS("data") my.df <- as.data.frame(dat) # Define UI for application that draws boxplot ui <- fluidPage( # Application title titlePanel("FingerTips QOF Prevalences"), # Input for year, area and indicator sidebarLayout( sidebarPanel( selectInput(inputId = "indicator", label = "Choose indicator:", choices = levels(my.df$IndicatorName), selected = "Hypertension: QOF prevalence (all ages)"), selectInput(inputId = "areatype", label = "Type of area:", choices = levels(my.df$AreaType), selected = "County & UA"), selectInput(inputId = "year", label = "Choose a year:", choices = levels(my.df$Timeperiod), selected = "2015/16")), # Show a plot of the generated distribution mainPanel( plotlyOutput("bPlot", height = 500, width = 1000) ) )) # Define server logic required to draw a histogram server <- function(input, output) { # draw the boxplot output$bPlot <- renderPlotly({ plot_ly(data = subset(my.df, my.df$IndicatorName == input$indicator & my.df$AreaType == input$areatype & my.df$Timeperiod == input$year), y = my.df$Value, color = my.df$ParentName, type = "box", colors = viridis_pal(alpha = 1, begin = 0, end = 1, direction = -1, option = "D")(3)) %>% layout(title = input$indicator, titlefont = list(family = "Helvetica", size = 16), xaxis = list(type = "category", tickfont = list(family = "Helvetica", size = 8)), yaxis = list(title = "Prevalence (%)", titlefont = list(family = "Helvetica", size = 12)))}) } # Run the application shinyApp(ui = ui, server = server)
How can I establish a default String value on a Tkinter Spinbox?
I have read a good solution for establishing a default numerical value on a Tkinter Spinbox widget when you use the from_ to options. But I have not seen a single one that can help establish a value (numerical or string) from a tuple. My code is as follows, and is intended to set a default value in a Tkinter Spinbox widget from a tuple: from Tkinter import * root = Tk() root.geometry('200x200+50+50') root.title('Prueba') t = ('One', 'Two', 'Three', 'Four', 'Five') v = t[3] var = StringVar() var.set(v) sb = Spinbox(root, values=t, textvariable=var, width=10) sb.place(x=5, y=15) root.mainloop() Another variant that I have tried is the following: from Tkinter import * root = Tk() root.geometry('200x200+50+50') root.title('Prueba') var = StringVar() var.set('Four') sb = Spinbox(root, ('One', 'Two', 'Three', 'Four', 'Five'), textvariable=var, width=10) sb.place(x=5, y=15) root.mainloop() The only way the set method works on Spinbox (and which I took from here) is the following and only works with numbers and within a range established as options in the Spinbox widget: from Tkinter import * root = Tk() root.geometry('200x200+50+50') root.title('Prueba') var = StringVar() var.set(4) sb = Spinbox(root, from_=1, to=5, textvariable=var, width=10) sb.place(x=5, y=15) root.mainloop() Can please anyone help me to find out how to establish a default value in a Tkinter Spinbox from a Tuple? I will appreciate that greatly!
If you move the line var.set(v) to be after creating the widget, the default value will be set. var = StringVar() sb = Spinbox(root, values=t, textvariable=var, width=10) var.set(v)